登录onActivityResult Android后Facebook SDK应用程序崩溃

时间:2016-03-04 16:06:49

标签: android android-fragments facebook-sdk-4.0 facebook-sdk-4.x

我允许在我的应用程序中登录facebook但是当我从Facebook登录webview按Ok时崩溃,当我再次打开应用程序时,我能够在我的屏幕上看到退出按钮???

在OnActivityResult中获取错误,它在那里崩溃..

我在这里写日志。

我的LoginFragment.java

loginButton =(LoginButton)findViewById(R.id.login_button);         loginButton.setFragment(本);

loginButton.setOnClickListener(new OnClickListener(){

        @Override
        public void onClick(View v) {
            checkLoginwithFB();

        }
    });

private void checkLoginwithFB() {

 LoginManager.getInstance().registerCallback(callbackManager,
                new FacebookCallback<LoginResult>() {
            public void onSuccess(LoginResult loginResult)
            {   
                LoginFragment.this.user = user;
                Profile profile = Profile.getCurrentProfile();
                RC_FB_SIGN_IN = loginButton.getRequestCode();
                Log.e("===FIrstname===>", "===FIrstname===>"+profile.getFirstName());
                if(profile !=null){
                    final String ID= profile.getId();
                    final String Name = profile.getName();

                    Log.e("===ID===>", "===ID===>"+profile.getId());
                    Log.e("===FIrstname===>","===FIrstname===>"+profile.getName());

                // It's possible that we were waiting for this.user to be
                // populated in order to post a
                // status update.
                //if (user != null) {

                    Log.e(TAG, ID);
                    Log.e(TAG,Name);
                     GraphRequest request = GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(), new GraphRequest.GraphJSONObjectCallback()
                    {


                        @Override
                        public void onCompleted(JSONObject object,
                                GraphResponse response) {
                            Map<String, String> map = new HashMap<String, String>();
                            map.put("url", URLS.LOGIN_WITH_FB_URL);
                            // map.put("email", "");
                            map.put("name", Name);
                            map.put("uid", ID);
                            new Controller(mainActivity, new AsyncTaskCompleteListener() {

                                @Override
                                public void onTaskCompleted(String doc,
                                        int requestCode) {
                                    try {
                                        JSONObject jsonObject = new JSONObject(doc);
                                        if (jsonObject.getInt("code") == 0) {           
                                            User user = new User();
                                            long l = Long.parseLong(ID);
                                            user.userID = jsonObject.getInt("user_id");                                 
                                            user.name = Name;
                                            user.email = "";
                                            user.isLogin = true;
                                            CoddyzUtils.saveUser(mainActivity, user);
                                            if (isReqLogin) {
                                                mainActivity.setResult(Activity.RESULT_OK);
                                                mainActivity.finish();
                                            } else {
                                                goToDeshboard(user);
                                            }
                                        }else{

                                        }

                                        //Toast.makeText(mainActivity, object.getString("message") + "", Toast.LENGTH_LONG).show();

                                    } catch (Exception e) {

                                        e.printStackTrace();
                                    }

                                }

                            },map);


                        }});

                    Bundle parameters = new Bundle();
                    parameters.putString("fields", "id,name");
                    request.setParameters(parameters);
                    request.executeAsync();
                //  Log.e(TAG, user.asMap().toString());

                            // }else{
                            // Toast.makeText(getActivity(), "Ankitsir",
                            // Toast.LENGTH_LONG).show();
                            // }
            }       // Toast.makeText(mainActivity, "FETCH" +
                    // user.asMap().toString(), Toast.LENGTH_LONG).show();
                 else {

                    }
            }



            @Override
            public void onCancel() {
                // TODO Auto-generated method stub

            }

            @Override
            public void onError(FacebookException error) {
                System.out.println("onError");
                Log.v("LoginActivity", error.getCause().toString());

            }

        });

    }

}




@Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {

         super.onActivityResult(requestCode, resultCode, data);


         if (FacebookSdk.isFacebookRequestCode(requestCode)) {


            Log.d(TAG,"Callback:"+CallbackManagerImpl.RequestCodeOffset.Login.toRequestCode());
             Log.d(TAG, "onActivityResult:" + requestCode + ":" + resultCode + ":" + data);
             callbackManager.onActivityResult(requestCode,
                        resultCode, data);

         }



    }

 03-04 21:30:57.923: E/AndroidRuntime(12641): FATAL EXCEPTION: main
03-04 21:30:57.923: E/AndroidRuntime(12641): Process: com.updatemania.foozup, PID: 12641
03-04 21:30:57.923: E/AndroidRuntime(12641): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=129742, result=-1, data=Intent { (has extras) }} to activity {com.updatemania.foozup/com.example.foo.LoginSignUpActivity}: java.lang.NullPointerException
03-04 21:30:57.923: E/AndroidRuntime(12641):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3532)
03-04 21:30:57.923: E/AndroidRuntime(12641):    at android.app.ActivityThread.handleSendResult(ActivityThread.java:3575)
03-04 21:30:57.923: E/AndroidRuntime(12641):    at android.app.ActivityThread.access$1300(ActivityThread.java:139)
03-04 21:30:57.923: E/AndroidRuntime(12641):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1341)
03-04 21:30:57.923: E/AndroidRuntime(12641):    at android.os.Handler.dispatchMessage(Handler.java:102)
03-04 21:30:57.923: E/AndroidRuntime(12641):    at android.os.Looper.loop(Looper.java:149)
03-04 21:30:57.923: E/AndroidRuntime(12641):    at android.app.ActivityThread.main(ActivityThread.java:5257)
03-04 21:30:57.923: E/AndroidRuntime(12641):    at java.lang.reflect.Method.invokeNative(Native Method)
03-04 21:30:57.923: E/AndroidRuntime(12641):    at java.lang.reflect.Method.invoke(Method.java:515)
03-04 21:30:57.923: E/AndroidRuntime(12641):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-04 21:30:57.923: E/AndroidRuntime(12641):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
03-04 21:30:57.923: E/AndroidRuntime(12641):    at dalvik.system.NativeStart.main(Native Method)
03-04 21:30:57.923: E/AndroidRuntime(12641): Caused by: java.lang.NullPointerException
03-04 21:30:57.923: E/AndroidRuntime(12641):    at example.foo.fragments.LoginFragment$2.onSuccess(LoginFragment.java:242)
03-04 21:30:57.923: E/AndroidRuntime(12641):    at example.foo.fragments.LoginFragment$2.onSuccess(LoginFragment.java:1)
03-04 21:30:57.923: E/AndroidRuntime(12641):    at com.facebook.login.LoginManager.finishLogin(LoginManager.java:510)
03-04 21:30:57.923: E/AndroidRuntime(12641):    at com.facebook.login.LoginManager.onActivityResult(LoginManager.java:194)
03-04 21:30:57.923: E/AndroidRuntime(12641):    at com.facebook.login.LoginManager$1.onActivityResult(LoginManager.java:141)
03-04 21:30:57.923: E/AndroidRuntime(12641):    at com.facebook.internal.CallbackManagerImpl.onActivityResult(CallbackManagerImpl.java:82)
03-04 21:30:57.923: E/AndroidRuntime(12641):    at com.updatemania.foozup.fragments.LoginFragment.onActivityResult(LoginFragment.java:377)
03-04 21:30:57.923: E/AndroidRuntime(12641):    at android.support.v4.app.FragmentActivity.onActivityResult(FragmentActivity.java:156)
03-04 21:30:57.923: E/AndroidRuntime(12641):    at android.app.Activity.dispatchActivityResult(Activity.java:5603)
03-04 21:30:57.923: E/AndroidRuntime(12641):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3528)
03-04 21:30:57.923: E/AndroidRuntime(12641):    ... 11 more

1 个答案:

答案 0 :(得分:0)

我猜你忘了从你活动的onActivityResult()调用CallbackManager.onActivityResult()。请参阅https://developers.facebook.com/docs/facebook-login/android