[英]Android Facebook SDK 3.0 Session State “Opening”
I am integrating Facebook's Login using their documentation. 我正在使用他们的文档整合Facebook的登录。 I am running into an issue where when i click the Facebook Login Widget the session changes to "Opening" and the app crashes 我遇到了一个问题,当我点击Facebook登录小部件时,会话变为“正在打开”,应用程序崩溃
My Layout for Facebook button 我的Facebook布局按钮
<com.facebook.widget.LoginButton
android:id="@+id/authButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
/>
The Fragment is 片段是
public class FacebookFragment extends Fragment {
private static final String TAG = "FacebookFragment";
private UiLifecycleHelper uiHelper;
private Session.StatusCallback callback = new Session.StatusCallback() {
@Override
public void call(final Session session, final SessionState state, final Exception exception) {
onSessionStateChange(session, state, exception);
}
};
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_main, container, false);
LoginButton authButton = (LoginButton) view.findViewById(R.id.authButton);
authButton.setFragment(this);
authButton.setReadPermissions(Arrays.asList("user_likes", "user_status"));
return view;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
uiHelper = new UiLifecycleHelper(getActivity(), callback);
uiHelper.onCreate(savedInstanceState);
}
@Override
public void onResume() {
super.onResume();
Session session = Session.getActiveSession();
if (session != null &&
(session.isOpened() || session.isClosed()) ) {
onSessionStateChange(session, session.getState(), null);
}
uiHelper.onResume();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
uiHelper.onActivityResult(requestCode, resultCode, data);
}
@Override
public void onPause() {
super.onPause();
uiHelper.onPause();
}
@Override
public void onDestroy() {
super.onDestroy();
uiHelper.onDestroy();
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
uiHelper.onSaveInstanceState(outState);
}
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
if (state.isOpened()) {
Log.i(TAG, "Logged in...");
} else if (state.isClosed()) {
Log.i(TAG, "Logged out...");
}
else
Log.i(TAG, session.toString());
}
} }
and in the activity i have implemented the required onActivityResult and retrieving the fragment 在活动中,我已经实现了所需的onActivityResult并检索了片段
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if(savedInstanceState == null) {
// Add the fragment on initial activity setup
mainFragment = new FacebookFragment();
getSupportFragmentManager()
.beginTransaction()
.add(android.R.id.content, mainFragment)
.commit();
} else {
// Or set the fragment from restored state info
mainFragment = (FacebookFragment) getSupportFragmentManager()
.findFragmentById(android.R.id.content);
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}
I thought maybe the issue lies with the Key Hash, but i followed the directions completely from the answer posted on this question Key hash for Android-Facebook app 我想也许问题可能在于Key Hash,但是我完全按照这个问题上的答案完成了指示Android-Facebook app的密钥哈希
Any lead on how to get the state to "Opened" would be greatly appreciated 任何关于如何让州“开放”的领导将不胜感激
The problem was in having android:clearTaskOnLaunch="true" on the activity that was doing the facebook login. 问题是在facebook登录的活动上有android:clearTaskOnLaunch =“true”。 The OnActivityResult was not able to be called. 无法调用OnActivityResult。 I was able to get a Exception when i ran the application in debug mode. 当我在调试模式下运行应用程序时,我能够获得异常。
Add session.addCallback(callback)
in your onResume()
: 在onResume()
添加session.addCallback(callback)
onResume()
:
super.onResume();
Session session = Session.getActiveSession();
session.addCallback(callback);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.