Domanda

I build an android app connect with facebook, which has a button. When I click the button, the app will call facebook.authorize to ask permission. After return from the ask permission screen, it should call onActivityResult method. But in my case, it never call this method. I found some similar question but all the solutions don't solve my case. Here's my code when user click the button:

facebook.authorize(this, new String[] { "read_friendlists" }, 
                new DialogListener() {
                    public void onComplete(Bundle values) {
                        Log.v("complete", "complete");
                        hideNeedLoginView();
                    }

                    public void onCancel() {
                        Log.v("cancel", "cancel");
                        hideNeedLoginView();
                    }

                    public void onFacebookError(FacebookError e) {
                        // TODO Auto-generated method stub
                        Log.v("error", "error");
                    }

                    public void onError(DialogError e) {
                        // TODO Auto-generated method stub
                        Log.v("error", "error");
                    }
                });

And onActivityResult method:

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

Since the onActivityResult not called, all the onComplete or onCancel method don't called either. The Intent.FLAG_ACTIVITY_NO_HISTORY is not defined so that's not the problem(this is mention on facebook page). If I set the activityCode to Facebook.FORCE_DIALOG_AUTH then when I clicked the button, the app not responding. And I have facebook app installed on the device. What should I do to call the onActivityResult method after authorize? Please someone help me with this since I can't find any solution anywhere.

È stato utile?

Soluzione

Hope following Code will help you.

private static final String[] PERMISSIONS = new String[]
    { "publish_stream", "read_stream", "offline_access" };

mFacebook = new Facebook(APP_ID); 
mFacebook.authorize(this, PERMISSIONS,new LoginDialogListener());


private final class LoginDialogListener implements
            com.facebook.android.Facebook.DialogListener
    {

        /**
         * Called when the dialog has completed successfully
         */
        public void onComplete(Bundle values)
        {
            // Process onComplete
            Log.d("FB Sample App", "LoginDialogListener.onComplete()");
            // Dispatch on its own thread
            mHandler.post(new Runnable()
            {
                public void run()
                {
                    mText.setText("Facebook login successful. Press Menu...");
                }
            });
        }

        public void onFacebookError(FacebookError error)
        {
            // Process error
            Log.d("FB Sample App", "LoginDialogListener.onFacebookError()");
        }

        public void onError(DialogError error)
        {
            // Process error message
            Log.d("FB Sample App", "LoginDialogListener.onError()");
        }

        public void onCancel()
        {
            // Process cancel message
            Log.d("FB Sample App", "LoginDialogListener.onCancel()");
        }
    }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top