When there’s no limit to what Android gets, there’s no limit to what Android does
Android Facebook integration
Steps for Facebook integration into your app
- Create your app on Facebook : http://www.facebook.com/developers/createapp.php
- Download Facebook SDK : http://developers.facebook.com/docs/guides/mobile
- Add Facebook SDK to your Android application

- Copy Application ID from Facebook

- Insert into your app Facebook controls as : LoginButton
- Insert extra code into your app
-
/*
-
-
<strong>public static final String APP_ID = "158312160885675";</strong>
-
-
private LoginButton mLoginButton;
-
private Facebook mFacebook;
-
private AsyncFacebookRunner mAsyncRunner;
-
-
/** Called when the activity is first created. */
-
@Override
-
public void onCreate(Bundle savedInstanceState) {
-
super.onCreate(savedInstanceState);
-
-
setContentView(R.layout.main);
-
mLoginButton = (LoginButton) findViewById(R.id.login);
-
-
mFacebook = new Facebook(APP_ID);
-
mAsyncRunner = new AsyncFacebookRunner(mFacebook);
-
-
SessionStore.restore(mFacebook, this);
-
SessionEvents.addAuthListener(new SampleAuthListener());
-
SessionEvents.addLogoutListener(new SampleLogoutListener());
-
mLoginButton.init(this, mFacebook);
-
}
-
-
<strong>@Override
-
protected void onActivityResult(int requestCode, int resultCode,
-
Intent data) {
-
mFacebook.authorizeCallback(requestCode, resultCode, data);
-
}
-
-
public class SampleAuthListener implements AuthListener {
-
-
public void onAuthSucceed() {
-
Toast.makeText(getBaseContext(), "AuthSucceed!", Toast.LENGTH_SHORT).show();
-
}
-
-
Toast.makeText(getBaseContext(), "AuthFail : " + error, Toast.LENGTH_SHORT).show();
-
}
-
}
-
-
public class SampleLogoutListener implements LogoutListener {
-
public void onLogoutBegin() {
-
Toast.makeText(getBaseContext(), "LogoutBegin", Toast.LENGTH_SHORT).show();
-
}
-
-
public void onLogoutFinish() {
-
Toast.makeText(getBaseContext(), "LogoutFinish", Toast.LENGTH_SHORT).show();
-
}
-
}
-
}
-
-
}</strong>
-
- Generate hash key for singleSignOn
keytool -exportcert -alias [alias] -keystore [keystore] | openssl sha1 -binary | openssl enc -a -e
For Windows users : you must install Cygwin and run command in the cygwin shell or use a linux VM. The result from Windows command will not work
- Put your hash key on Facebook application page – mobile tab

- Run your app
| Print article | This entry was posted by Sebastian on 2011/01/21 at 11:09, and is filed under Android development. Follow any responses to this post through RSS 2.0. Both comments and pings are currently closed. |
Comments are closed.
