-
Notifications
You must be signed in to change notification settings - Fork 17
Android setup
- Create a new project:
cd workspace
nme create project "fr.hyperfiction.fbexample" "Hyperfiction"
- Copy the extension folder:
git clone git://github.com/hyperfiction/HypFacebook.git
Now you have:
workspace/
Fbexample/
Assets/
nme.svg
Source/
Main.hx
Fbexample.hxproj
project.nmml
HypFacebook/
...
- Go to your new project folder and test if you compile
cd Fbexample
nme test android -debug
Now you have:
workspace/
Fbexample/
Assets/
nme.svg
Export/
android/
bin/
AndroidManifest.xml
build.xml
src/
haxe/
obj/
Source/
Main.hx
Fbexample.hxproj
project.nmml
HypFacebook/
...
- Create a template folder:
cd workspace/Fbexample
mkdir -p Templates/android/res
Now you have:
workspace/
Fbexample/
Assets/
nme.svg
Export/
android/
bin/
AndroidManifest.xml
build.xml
src/
haxe/
obj/
Source/
Main.hx
Templates/
android/
res/
Fbexample.hxproj
project.nmml
HypFacebook/
...
- Copy the AndroidManifest.xml to the template folder:
cd workspace/Fbexample
cp Export/android/bin/AndroidManifest.xml Templates/android
Now you have:
workspace/
Fbexample/
Assets/
nme.svg
Export/
android/
bin/
AndroidManifest.xml
build.xml
src/
haxe/
obj/
Source/
Main.hx
Templates/
android/
res/
AndroidManifest.xml
Fbexample.hxproj
project.nmml
HypFacebook/
...
- Edit your project.nmml file:
cd workspace/Fbexample
vim project.nmml
Add this lines:
<include path="../HypFacebook" />
<template path="Templates/android/AndroidManifest.xml" rename="AndroidManifest.xml"/>
<template path="../HypFacebook/templates/android/MainActivity.java"
rename="src/fr/hyperfiction/fbexample/MainActivity.java"/>
- Edit the AndroidManifest.xml:
cd workspace/Fbexample/Templates/android
vim AndroiManifest.xml
Add this line:
<activity android:name="com.facebook.LoginActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:label="::APP_TITLE::" />
Now you have:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="preferExternal" android:versionCode="13" android:versionName="1.0.0" package="fr.hyperfiction.fbexample">
<application android:label="Fbexample" android:debuggable="true" android:icon="@drawable/icon">
<activity android:name="com.facebook.LoginActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:label="::APP_TITLE::" />
<activity android:name="MainActivity" android:label="Fbexample" android:configChanges="keyboard|keyboardHidden|orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="ouya.intent.category.GAME"/>
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="8"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
- Start coding:
cd workspace/Fbexample/Source
vim Main.hx
import nme.display.Sprite;
import fr.hyperfiction.HypFacebook;
class Main extends Sprite {
var fb : HypFacebook;
public function new () {
super ();
connectToFacebook( );
}
function connectToFacebook( ) : Void {
fb = new HypFacebook( "" );
var session_is_valid = fb.connect( false ); // false to disallow login UI
if( session_is_valid ) {
_doFacebookStuff( );
} else {
fb.addEventListener( HypFacebookEvent.OPENED, _onFbOpened );
fb.connect( true ); // true to allow login UI
}
}
function _onFbOpened( _ ) {
fb.removeEventListener( HypFacebookEvent.OPENED, _onFbOpened );
_doFacebookStuff( );
}
function _doFacebookStuff( ) {
fb.addEventListener( HypFacebookRequestEvent.GRAPH_REQUEST_RESULTS, _onGraphResults );
fb.call( GRAPH_REQUEST("/me") );
}
function _onGraphResults( event : HypFacebookRequestEvent ) : Void {
trace( 'sResult:'+event.sResult );
}
}
- Test to get the PXR:
nme test android -debug
The facebook login won't work, just copy your app package name and your pxr from the ouput:
I/trace (32187): nme_key_hash : +fr.hyperfiction.fbexample
I/trace (32187): PXR : pRqGr00vyKadfeNtfCttxWWk8JflaJk=
-
You should now create or update your facebook app:
- Tick "Native Android App"
- Paste the package name:
fr.hyperfiction.fbexample
- Paste the PXR in "Key Hashes":
pRqGr00vyKadfeNtfCttxWWk8JflaJk=
- Save Changes
-
Update your code with your app id:
fb = new HypFacebook( "6233362678093339" );
- Test again:
nme test android -debug
It works ;)
- If it doesn't works:
Be careful when testing your app. For some user having the Facebook app installed prevents them to test their app with sandbox mode on. Try with a different permission (admin/developer/tester...) or disable the sandbox mode.
The first time it will open a web view or directly ask you the basic permissions if you have the Fb app installed. Then it will trace the result of the Graph request. The second time it will directly trace the result as it cache the Facebook token.