Search code examples
javaandroidfacebookfacebook-graph-apifacebook-android-sdk

onActivityResult requestcode Facebook SDK


I'm building an Android app which uses the Facebook SDKso people can share URL's. I'm using onActivityResult for multiple things in my activity, so I'm using a switch on requestCode so that I know what to do with every activityresult. How do I get the proper requestCode when for example I cancel sharing a facebook post? This is my code at the moment:

import com.facebook.CallbackManager;

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

    switch (requestCode) {
        case 1: 
        ... doing some not-facebook-related stuff here
        case 2:
        ... doing some other not-facebook-related stuff here


//      case ??? : 
//      callbackManager.onActivityResult(requestCode, resultCode, data);

So what is the right requestCode and how do I get this?


Solution

  • Try using a sharedialog instead

    new ShareDialog(this).registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
                @Override
                public void onSuccess(Sharer.Result result) {
    
                }
    
                @Override
                public void onCancel() {
    
                }
    
                @Override
                public void onError(FacebookException error) {
    
                }
            });
    

    When you cancel share you get to onCancel callback. Also uncomment this

    callbackManager.onActivityResult(requestCode, resultCode, data);
    

    from onActivityResult method.