登录onActivityResult Android后Facebook SDK应用程序崩溃
Posted
技术标签:
【中文标题】登录onActivityResult Android后Facebook SDK应用程序崩溃【英文标题】:Facebook SDK app crash after login onActivityResult Android 【发布时间】:2016-03-04 16:06:48 【问题描述】:我允许在我的应用程序中登录 facebook,但是当我从 Facebook Login webview 中按 Ok 并且当我再次打开应用程序时我能够在我的屏幕上看到注销按钮时崩溃???
在 OnActivityResult 中出现错误,它在那里崩溃..
我把我的日志放在这里。
我的 LoginFragment.java
loginButton = (LoginButton) findViewById(R.id.login_button); loginButton.setFragment(this);
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 ResultInfowho=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
【问题讨论】:
显示LoginFragment
我可以放在这里吗???
把它作为问题的一部分:)
【参考方案1】:
我猜你忘了从你的活动的 onActivityResult() 调用 CallbackManager.onActivityResult()。参考https://developers.facebook.com/docs/facebook-login/android
【讨论】:
我已经将 CallbackManager.onActivityResult() 放入代码中,请检查。 而你的数据对象不为空? 是什么意思?我猜它是空的 根据您的日志消息,数据不为空。另一种猜测 - 您应该从片段 onActivityResult() 中调用 CallbackManager.onActivityResult(),而不是活动之一。以上是关于登录onActivityResult Android后Facebook SDK应用程序崩溃的主要内容,如果未能解决你的问题,请参考以下文章
YSDK1.8X版本后QQ登录onActivityResult没有触发
YSDK1.8X版本后QQ登录onActivityResult没有触发
YSDK1.8X版本后QQ登录onActivityResult没有触发
GoogleSignIn 重复登录弹出窗口并且不会转到 Android API 30 的 onActivityResult