FacebookSdk.sdkInitialize (Context) is deprecated

I use facebook-android-sdk-4.19.0 in Android Studio, and I followed the quick Facebook guide at https://developers.facebook.com/docs/android/getting-started (click the Quick Start button to log in to your facebook account). The guide said to copy and paste the following code into a snippet for tracking application logs

import com.facebook.FacebookSdk; import com.facebook.appevents.AppEventsLogger; public class MyApplication extends Application { @Override public void onCreate() { super.onCreate(); FacebookSdk.sdkInitialize(getApplicationContext()); AppEventsLogger.activateApp(this); } } 

However, when I copy the code in android studio, it seems that all the methods of FacebookSdk.sdkInitialize () are out of date. The documentation here https://developers.facebook.com/docs/reference/android/current/class/FacebookSdk/ does not tell you which method to use to initialize sdk instead of sdkInitialize (). Which method should be used?

+81
android deprecated facebook facebook-android-sdk
Jan 26 '17 at 22:47
source share
4 answers

From the documentation for updating the SDK:

Now the Facebook SDK is automatically initialized when the application starts. if you use the Facebook SDK in the main process and don’t need a callback when the initialization of the SDK is completed, now you can delete the FacebookSDK.sdkInitialize calls. If you need a callback, you must manually call the callback in your code.

Refer to: https://developers.facebook.com/docs/android/upgrading-4x

UPDATE

In SDK 4.22, the title , description , caption and image FBSDKShareLinkContent are deprecated. Try to remove them from use.

+110
Jan 26 '17 at 22:52
source share
 FacebookSdk.sdkInitialize(getApplicationContext()); 

This method is deprecated, so just delete this line of code in your class. because, according to the latest versions of Facebook, we don’t need to initialize the SDK manually, it initializes by itself.

+6
Feb 01 :
source share

So instead of calling obsolete methods, you can call AppEventsLogger.activateApp(Application) inside the onCreate () application class

 public class MyApplication extends Application{ @Override public void onCreate() { super.onCreate(); AppEventsLogger.activateApp(getApplication()); } } 
+4
Oct 05 '17 at 4:50
source share

I had the same issue, and here is how I resolve it: Put this line of code in the manifest file

  <application android:label="@string/app_name" ...> ... <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/> ... </application> 

https://developers.facebook.com/docs/android/getting-started Thanks

-7
Apr 17 '17 at 10:02
source share



All Articles