2016-08-04 6 views
1

ich diesen Fehler haben zu rufen, wenn die Facebook-SDK Implementierung und i tried-many of the - solutions aber keiner arbeitete dann. Dies ist, was ich habe:Das SDK wurde nicht initialisiert, stellen Sie sicher, FacebookSdk.sdkInitialize() erste

@Override 
    protected void onCreate(@Nullable Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     FacebookSdk.sdkInitialize(getApplicationContext()); 
     callbackManager = CallbackManager.Factory.create(); 
     setContentView(R.layout.activity_name_layout); 

LoginButton loginButton = (LoginButton)findViewById(R.id.fb_login_button); 
     loginButton.setReadPermissions(Arrays.asList("public_profile", "email")); 
     loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() { 
      @Override 
      public void onSuccess(LoginResult loginResult) { 

      } 

      @Override 
      public void onCancel() { 

      } 

      @Override 
      public void onError(FacebookException error) { 

      } 
     }); 

    @Override 
     protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
      super.onActivityResult(requestCode, resultCode, data); 
      callbackManager.onActivityResult(requestCode, resultCode, data); 
     } 

Graddle:

compile 'com.facebook.android:facebook-android-sdk:4.8.0' 

Manifest:

<activity android:name="com.facebook.FacebookActivity" 
      android:configChanges= 
       "keyboard|keyboardHidden|screenLayout|screenSize|orientation" 
      android:theme="@android:style/Theme.Translucent.NoTitleBar" 
      android:label="@string/app_name" /> 

Schaltfläche Layout:

<LinearLayout 

    xmlns:facebook="http://schemas.android.com/apk/res-auto" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:background="@color/colorPrimaryDark" 
    android:padding="10dp" 
    android:layout_height="match_parent"> 

    <com.facebook.login.widget.LoginButton 
     android:layout_marginTop="10dp" 
     android:id="@+id/fb_login_button" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 

     ></com.facebook.login.widget.LoginButton> 
</LinearLayout> 

Kann mir jemand darauf hinweisen, was im falsch zu machen ?

+2

sauber und neu aufgebaut – kgandroid

Antwort

0

Die docs haben Sie es in der Anwendungsklasse setzen jetzt:

public class MyApplication extends Application { 
    @Override 
    public void onCreate() { 
     super.onCreate(); 
     // Initialize the SDK before executing any other operations, 
     FacebookSdk.sdkInitialize(getApplicationContext()); 
     AppEventsLogger.activateApp(this); 
    } 
} 

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

Verwandte Themen