I am integrating the Facebook Login in my Android Application and when I click on the Login button and allow the required permission it gives me Unexpected call to LoginManager.onActivityResult .
permissions that I am requesting are "public_profile","business_management","read_insights"
I have followed all the instruction as per this question but still facing the same error
Facebook Android SDK v2.3 Unexpected call to LoginManager.onActivityResult
public class FacebookLogIn extends AppCompatActivity implements View.OnClickListener {
private static final String TAG = "FacebookLogIn";
private List<String> permissions = Arrays.asList("public_profile","business_management","read_insights");
private CallbackManager callbackManager;
ViewPager viewPagerFragment;
SplashViewPagerAdapter viewPagerAdapter;
Button btnLogin;
FrameLayout frameLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_log_in);
viewInIt();
viewPagerSetUp();
doAuth();
//automatically logIn if access Token available and not expired else perform doAuth().
AccessToken accessToken = MyTokens.getAccessToken();
boolean isLoggedIn = accessToken != null && !accessToken.isExpired() && accessToken.getPermissions().contains("read_insights") && accessToken.getPermissions().contains("business_management");
if (isLoggedIn){
//if access token not expired and permission granted then start AppSelection Activity
startActivity(new Intent(FacebookLogIn.this, AppSelection.class));
//and close the current activity
finish();
}
}
private void viewInIt(){
btnLogin=findViewById(R.id.btnFbLogin);
btnLogin.setOnClickListener(this);
}
/*
--------------------------------------Login button------------------------------------------------------
*/
@Override
public void onClick(View v) {
LoginManager.getInstance().logInWithReadPermissions(this, permissions);
}
private void doAuth() {
//callbackManager for facebook logIn
callbackManager = CallbackManager.Factory.create();
LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
//start AppSelection Activity
startActivity(new Intent(FacebookLogIn.this,AppSelection.class));
//and close the current activity
finish();
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException exception) {
exception.printStackTrace();
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
I am getting this error code when press the Login button allow the permission
W/System.err: Unexpected call to LoginManager.onActivityResult
W/System.err: at com.facebook.login.LoginManager.onActivityResult(LoginManager.java:232)
at com.facebook.login.LoginManager$1.onActivityResult(LoginManager.java:174)
W/System.err: at com.facebook.internal.CallbackManagerImpl.onActivityResult(CallbackManagerImpl.java:91)
at com.greenlab.audiencenetwork.FacebookLogIn.onActivityResult(FacebookLogIn.java:110)
at android.app.Activity.dispatchActivityResult(Activity.java:7121)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4175)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4222)
at android.app.ActivityThread.-wrap20(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1581)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6238)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:933)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
I had the same error, and did a lot til it worked, however I might not be able to say specifically what fixed it, but its probably not code. My best guess is you need to Verify your Dev Account as Individual or Business Account https://developers.facebook.com/docs/development/release/individual-verification As written, the changes take effect immediatetely, so when I got the email that my account was verified successfully, I went to my app, tried the oAuth, it worked.
I'll point out other things I did:
tools:replace="android:value"
on that meta dataSo whether its all of them or one of them, I encourage you to check the list.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.