Skip to content Skip to sidebar Skip to footer

Facebook Callbackmanager Method Onactivityresult Not Calling In Fragment Onactivityresult Method

I have implemented Facebook integration and it's working fine in part of initialization even Facebook APPID is also fine with application. So let me explain in more detail : I have

Solution 1:

According to facebook documentations, In a fragment, you should call this method

> Java 

loginButton.setFragment(this);
> Kotlin

loginButton.fragment = this

Solution 2:

Could'nt find solution in stackoverflow so, i have done this my own

-> add callbackmanager in a java class globalvaluesclass,which can be accessible by both activity and fragment

->in onCreate of your parent activity add this Globalvalues.callbackManager = CallbackManager.Factory.create();

->in your fragment start your facebook login class with Globalvalues.callbackManager

LoginManager.getInstance().registerCallback(Globalvalues.callbackManager, new FacebookCallback() {

#all that fb stuff

}

-> override onactivity result in your parent activity.

@Overridepublic void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

       fragment.customOnActivityResult(requestCode, resultCode, data);

}

and in your fragment add a function for example as shown below

      publicstatic void customOnActivityResult(){
          super.onActivityResult(requestCode, resultCode, data);
    Globalvalues.callbackManager.onActivityResult(requestCode, resultCode,
      data);

  }

                                                       and you're Welcome.

Solution 3:

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

Solution 4:

I had this problem when I used following code to initiate login:

LoginManager.getInstance().logInWithReadPermissions(getActivity(), Arrays.asList(EMAIL));

so I explicitly asked to use Activity instance as receiver of login results. The solution is to provide fragment instance, for which appropriate overloaded method exists:

LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList(EMAIL));

This assumes call is from within fragment.

Solution 5:

I also had the same problem, initially I was not setting the fragment reference while setting the permissions, so I modified my call like below:

loginManagerFb.logInWithReadPermissions(
     this,
     listOf("public_profile", "email")
)

But still I was facing the issue, the callbackManager was not getting called for me, so I added onActivityResult() like below:

overridefunonActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)
    callbackManager.onActivityResult(requestCode, resultCode, data)
}

The issue with the above code was that the onActivityResult is now deprecated, so to remove the deprecated code I modified the code as below:

val loginManagerFb = LoginManager.getInstance()
     loginManagerFb.logInWithReadPermissions(
         this,
         callbackManager,
         listOf("public_profile", "email")
    )

The change that was required to remove the deprecated code was to pass the callbackManager reference while logInWithReadPermissions()

Used the facebook latest library version:

implementation "com.facebook.android:facebook-android-sdk:12.0.0"

Post a Comment for "Facebook Callbackmanager Method Onactivityresult Not Calling In Fragment Onactivityresult Method"