我制作了一个需要使用 Facebook 登录的 android 应用程序,一旦身份验证成功,我需要转到另一个意图。所以我从这里下载了 Facebook Android SDK 。
下载并导入 Eclipse 后,我SessionLoginExample
从那个 SDK 扩展了。在我的模拟器中它对我来说工作正常,我可以使用它登录到 Facebook 应用程序,而且一旦我登录,它也会进入另一个 Intent。
问题陈述:-
但是当我在真正的Android手机上安装应用程序后,问题就出现了。在 Android 手机上安装它之后,一旦打开 Facebook 登录页面,将我的用户名和密码输入其中,它就不会再有其他意图,并且有时我的控制台也会出现异常。之后,每次我收到一条消息Facebook has stopped working
,然后我都会收到我的Application has forced closed
.
我注意到的另一件事是 - 一旦我在 Android Phone 中打开我的应用程序,我总是在控制台中收到消息,说我Login Failed
什至没有在 Facebook 页面中输入我的用户名和密码。
下面是我使用的代码SessionLoginExample
-
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment, container, false);
buttonLoginLogout = (Button) view.findViewById(R.id.buttonLoginLogout);
textInstructionsOrLink = (TextView) view.findViewById(R.id.instructionsOrLink);
Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);
Session session = Session.getActiveSession();
if (session == null) {
if (savedInstanceState != null) {
session = Session.restoreSession(getActivity(), null, statusCallback,
savedInstanceState);
}
if (session == null) {
session = new Session(getActivity());
}
Session.setActiveSession(session);
if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) {
session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
}
}
updateView();
return view;
}
@Override
public void onStart() {
super.onStart();
Session.getActiveSession().addCallback(statusCallback);
}
@Override
public void onStop() {
super.onStop();
Session.getActiveSession().removeCallback(statusCallback);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(getActivity(), requestCode, resultCode, data);
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Session session = Session.getActiveSession();
Session.saveSession(session, outState);
}
private void updateView() {
Session session = Session.getActiveSession();
if (session.isOpened()) {
// After login is successful, I am going to another Intent
Intent thesisProject = new Intent(getActivity(), ThesisProjectAndroid.class);
startActivity(thesisProject);
} else {
Log.d(TAG_LOGIN_FAILED,
"There is something wrong with your Facebook account. Please try again.");
textInstructionsOrLink.setText(R.string.instructions);
buttonLoginLogout.setText(R.string.login);
buttonLoginLogout.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
onClickLogin();
}
});
}
}
private void onClickLogin() {
Session session = Session.getActiveSession();
if (!session.isOpened() && !session.isClosed()) {
session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
} else {
Session.openActiveSession(getActivity(), this, true, statusCallback);
}
}
private void onClickLogout() {
Session session = Session.getActiveSession();
if (!session.isClosed()) {
session.closeAndClearTokenInformation();
}
}
private class SessionStatusCallback implements Session.StatusCallback {
@Override
public void call(Session session, SessionState state, Exception exception) {
updateView();
}
}
}
而且我也低于例外 -
01-30 11:06:08.400: E/AndroidRuntime(7463): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=64206, result=0, data=null} to activity {com.facebook.samples.sessionlogin/com.facebook.LoginActivity}: java.lang.NullPointerException
任何人都可以帮我解决为什么它会发生在我的手机上吗?