Reputation: 1347
I have this error when implementing the Facebook SDK and i tried - many of the - solutions but none of then worked. This is what i have:
@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" />
Layout button:
<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>
Can someone point me out what im doing wrong?
Upvotes: 6
Views: 15410
Reputation: 359
First of all you need to use maveen() and both dependencies(here you forget to add annotation dependencies) of Facebook Audience Network, After this you your all problem will be solved.
Do not implement helper class , it is deprecated.
In Android Studio, make sure that mavenCentral() or jcenter() is included in your project's list of repositories. Repositories are defined in your project's module-level build.gradle file.
repositories {
mavenCentral()
jcenter()
}
Next, add the following implementation dependencies (check latest sdk- https://developers.facebook.com/docs/audience-network/guides/adding-sdk/android ) to your project's list of dependencies. Dependencies are also defined in your project's module-level build.gradle file. Note that annotation support is required by the Audience Network SDK.
dependencies {
implementation 'com.android.support:support-annotations:28.0.0'
implementation 'com.facebook.android:audience-network-sdk:5.+'
}
After at all do not implement helper classs. Replace it to latest method, call AudienceNetworkAds.initialize(this)
in onCreate
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AudienceNetworkAds.initialize(this);
}
Thanks Happy Coding :)
Upvotes: 0
Reputation: 5899
The docs have you set it in the Application class now:
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/
Upvotes: 4