Facebook SDK for Android Upgrade Guide
Upgrading the Android SDK from 4.17.0 to 4.18.0
No special steps are required to upgrade to 4.18.0.
Upgrading the Android SDK from 4.16.1 to 4.17.0
If you use Account Kit Advanced UI, make sure to handle the three new screens as noted in the docs.
Upgrading the Android SDK from 4.16.0 to 4.16.1
No special steps are required to upgrade to 4.16.1.
Upgrading the Android SDK from 4.15.0 to 4.16.0
No special steps are required to upgrade to 4.16.0.
Upgrading the Android SDK from 4.14.1 to 4.15.0
Classes and methods associated with App and Game Groups have been deprecated. Please take appropriate action to remove usage of them.
Upgrading the Android SDK from 4.14.0 to 4.14.1
No special steps are required to upgrade to 4.14.1.
Upgrading the Android SDK from 4.13.2 to 4.14.0
No special steps are required to upgrade to 4.14.0.
Upgrading the Android SDK from 4.13.1 to 4.13.2
No special steps are required to upgrade to 4.13.2.
Upgrading the Android SDK from 4.13.0 to 4.13.1
No special steps are required to upgrade to 4.13.1.
Upgrading the Android SDK from 4.12.1 to 4.13.0
No special steps are required to upgrade to 4.13.0.
Upgrading the Android SDK from 4.12.0 to 4.12.1
No special steps are required to upgrade to 4.12.1.
Upgrading the Android SDK from 4.11.0 to 4.12.0
No special steps are required to upgrade to 4.12.0.
Upgrading the Android SDK from 4.10.1 to 4.11.0
Instead of calling AppEventsLogger.activateApp and AppEventsLogger.deactivateApp in each Activity, you should now just call AppEventsLogger.activateApp(Application) from your Application's onCreate method and the SDK will automatically track sessions for you.
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
FacebookSdk.sdkInitialize(getApplicationContext());
AppEventsLogger.activateApp(this);
}
}
Note the v4.11 SDK targets v2.6 of the Graph API.
Upgrading the Android SDK from 4.10.0 to 4.10.1
No special steps are required to upgrade to 4.10.1.
Upgrading the Android SDK from 4.9.0 to 4.10.0
If you relied on graph requests being localized. You now have to specify the locale parameter manually.
Upgrading the Android SDK from 4.8.2 to 4.9.0
No special steps are required to upgrade to 4.9.0.
Upgrading the Android SDK from 4.8.1 to 4.8.2
No special steps are required to upgrade to 4.8.2.
Upgrading the Android SDK from 4.8.0 to 4.8.1
No special steps are required to upgrade to 4.8.1.
Upgrading the Android SDK from 4.7.0 to 4.8.0
No special steps are required to upgrade to 4.8.0.
Upgrading the Android SDK from 4.6.0 to 4.7.0
The SDK now targets v2.5 of the Graph API. Please review the Graph API changelog for details.
The GameRequestContent 'to' member has been deprecated and replaced with Recipients.
Upgrading the Android SDK from 4.5.1 to 4.6.0
The SDK now requires a minimum sdk of API level 15 or above.
Upgrading the Android SDK from 4.5.0 to 4.5.1
No special steps are required to upgrade to 4.5.1.
Upgrading the Android SDK from 4.4.1 to 4.5.0
No special steps are required to upgrade to 4.5.0.
Upgrading the Android SDK from 4.4.0 to 4.4.1
No special steps are required to upgrade to 4.4.1.
Upgrading the Android SDK from 4.3.0 to 4.4.0
The SDK now targets v2.4 of the Graph API. Please review the Graph API changelog for details. For example, the number of default fiends returned by Graph endpoints have been reduced and you should always explicitly ask for the fields you need.
Upgrading the Android SDK from 4.2.0 to 4.3.0
No special steps are required to upgrade to 4.3.0.
Upgrading the Android SDK from 4.1.2 to 4.2.0
The method to set the custom request code for the login button has been removed.
Upgrading the Android SDK from 4.1.1 to 4.1.2
No special steps are required to upgrade to 4.1.2.
Upgrading the Android SDK from 4.1.0 to 4.1.1
No special steps are required to upgrade to 4.1.1.
Upgrading the Android SDK from 4.0.1 to 4.1.0
There is one breaking change from 4.0.
Style attr tags are now namespaced to avoid conflicts. Apps will need to add the namespace "com_facebook_" to their existing facebook sdk style attrs.
For example.
facebook:preset_size="small"
becomes
facebook:com_facebook_preset_size="small"
Upgrading the Android SDK from 4.0 to 4.0.1
No special steps are required to upgrade to 4.0.1.
Upgrading the Android SDK from 3.x to 4.x
The Facebook SDK for Android v4.0 is a major version upgrade which features:
- Improved login programming model.
- Improved sharing programming model, and more ways to share without needing an access token.
- Improved error handling and error recovery mechanism.
- The SDK now allows developers to run ProGuard across the entire project, reducing the footprint in the final APK.
Install and Setup Updates
For full instructions on install and setup for 4.x, see Getting Started Android SDK.
Set up the app ID in
AndroidManifest.xmlas in 3.xIf you use any native dialogs such as Share or Invite add your app name to
AndroidManifest.xml:
<meta-data android:name="com.facebook.sdk.ApplicationName"
android:value="@string/app_name" LoginActivityis replaced byFacebookActivity. Add this inAndroidManifest.xml:
<activity android:name="com.facebook.FacebookActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name" />- To initialize the SDK, call
FacebookSdk.sdkInitializefromonCreateinActivityorApplication:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(this.getApplicationContext());
}- See
FacebookSdkclass for other configurations you can set at app launch.
Login Updates
For more information on Login in 4.x, also see Facebook Login for Android.
Session Removed -
AccessToken,LoginManagerandCallbackManagerclasses supercede and replace functionality in theSessionclass.Access Tokens - You can load
AccessToken.getCurrentAccessTokenwith the SDK from cache or if the app is cold launched from an app bookmark. For instructions, see Facebook Login for Android, Get Current Token.Login Button - The easiest way to add Login is to use the
LoginButtonin 4.x. See Facebook Login for Android, Add Facebook Login.UserSettingsFragmentclass has been removed from the SDK.LoginManageris a singleton instance, and works with theAccessToken'scurrentAccessToken. After login the SDK setscurrentAccessToken. To get additional permissions call thelogInWith...methods.LogInWith...methods always open a prompt UI if necessary. There's no equivalent to theSession.openActiveSessionFromCacheorSession.OpenActiveSession(Activity, boolean, StatusCallback). Instead, you should checkAccessToken.getCurrentAccessToken()at onCreate(), and if not null, skip login.AccessTokenbroadcast events when it is set, unset or updated. Use theAccessTokenTrackerto receive these events. See Facebook Login for Android, Track Access Tokens.currentAccessTokenautomatically caches when the SDK sets it.ProfileTracker.getCurrentProfilereturns the current logged in user.ProfileTrackerreturns events if the logged in user changes. see Facebook Login for Android, Track Current Profile.CallbackManager.onActivityResultreplacesSession.onActivityResultandUiLifecycleHelper.onActivityResult. See Facebook Login for Android, Register a Callback.
Graph API Updates
For more information on Android and Graph API in 4.x, also see Using the Graph API, Android.
RequestandResponseclasses in v3 are now calledGraphRequestandGraphResponse.- Methods and constructors that used to take
Sessionin v3 now takeAccessTokenor implicitly useAccessToken.getCurrentAccessTokenif you don't provide one. - Methods like
newMeRequest,newMyFriendsRequestreturned a typed parameter in the callback likeGraphUserorList<GraphUser>now pass in genericJSONObjectandJSONArrayinstead.
The old version:
Request request = Request.newMeRequest(session, new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
profilePictureView.setProfileId(user.getId());
}
}
}).executeAsync();
The new version
GraphRequest request = GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject user, GraphResponse response) {
if (user != null) {
profilePictureView.setProfileId(user.optString("id"));
}
}
}).executeAsync();
FacebookRequestErrorclass has more error handling information. See Using the Graph API, Android.- Graph API calls now also have the ability to pass back debug information for developers during testing. You can set the
LoggingBehavior.GRAPH_API_DEBUG_WARNINGorLoggingBehavior.GRAPH_API_DEBUG_INFOflags in theFacebookSdkclass.
Sharing Updates
For more information on Android and Sharing in 4.x, also see Sharing on Android.
- Content Model - Each dialog can show a
Contentobject which represents the data for that dialog. For exampleAppInvitesDialogshows theAppInvitesContent. EachContentclass also has a correspondingBuilderto help you build the content object. These are in thecom.facebook.share.modelpackage. See Sharing on Android, Modeling Content. - Dialog Classes - There are now individual
Dialogclasses for every type of dialog that Facebook offers. They are in thecom.facebook.share.widgetpackage. See Sharing on Android, Add Sharing UIs. - Feed Dialog - Instead of using the Feed Dialog directly (via
WebDialog.FeedDialogBuilderin v3.x), you should now useShareDialog, which will use the native Share Dialog in the Facebook app if installed, and fall back to a webview. If you explicitly want to show only the Feed Dialog, you can useShareDialog.show(content, ShareDialog.Mode.FEED); - Buttons - There are also the
SendButtonandShareButtonwhich are drop-in replacement buttons for theMessageDialogandShareDialogrespectively.
App Events Updates
No major API changes, but classes are now in com.facebook.appevents.