我无法真正描述我的问题,它曾经正常工作,但现在我不能再登录了,我坚持这个错误:
E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.UnsupportedOperationException: Session: an attempt was made to request new permissions for a session that has been closed.
我应该在哪里放置权限?
这是我的登录代码
private boolean isResumed = false;
private UiLifecycleHelper uiHelper;
private Session.StatusCallback callback =
new Session.StatusCallback() {
@Override
public void call(Session session,
SessionState state, Exception exception) {
onSessionStateChange(session, state, exception);
}
};
SharedPreferences userpref;
SharedPreferences.Editor editor;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
uiHelper = new UiLifecycleHelper(this, callback);
uiHelper.onCreate(savedInstanceState);
setContentView(R.layout.viewpager_layout);
userpref = ControlActivity.this.getSharedPreferences("UserPref", 0); // 0 - for private mode
editor = userpref.edit();
//facebook login
Log.v("test","Main oncreate facebook");
FragmentManager fm = getSupportFragmentManager();
loginfragment = fm.findFragmentById(R.id.splashFragment);
FragmentTransaction transaction = fm.beginTransaction();
transaction.hide(loginfragment);
transaction.commit();
//end facebook login
// Create fragments.
//Loading fragments in viewpager*******************************************************
Log.v("test","Main oncreate");
PrepareFragments();
_viewPager = (ViewPager) findViewById(R.id.viewpager);
_viewPager.setOffscreenPageLimit(0);
_viewPager.setAdapter(_fragmentPagerAdapter);
_viewPager.setCurrentItem(1);
}
OnSessionStateChange方法
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
// Only make changes if the activity is visible
if (isResumed) {
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
// Get the number of entries in the back stack
int backStackSize = manager.getBackStackEntryCount();
// Clear the back stack
for (int i = 0; i < backStackSize; i++) {
manager.popBackStack();
}
if (state.isOpened()) {
// If the session state is open:
// Show the authenticated fragment
if (session.isOpened()) {
Request.executeMeRequestAsync(session,
new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
_viewPager = (ViewPager) findViewById(R.id.viewpager);
_viewPager.setOffscreenPageLimit(0);
_viewPager.setAdapter(_fragmentPagerAdapter);
_viewPager.setCurrentItem(1);
Log.v("test","pref"+userpref.getString("user_firstname","null"));
}
}
}
);
}
transaction.hide(loginfragment);
transaction.addToBackStack(null);
} else if (state.isClosed()) {
//requesting permission
Session.NewPermissionsRequest newPermissionsRequest = new Session
.NewPermissionsRequest(this, Arrays.asList("basic_info", "email"));
session.requestNewReadPermissions(newPermissionsRequest);
transaction.show(loginfragment);
}
transaction.commit();
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
uiHelper.onActivityResult(requestCode, resultCode, data);
}
答案 0 :(得分:0)
你的设备上有facebook应用吗?是的然后只是从Facebook应用程序注销 然后完全卸载您的应用。然后安装您的应用程序并检查。多数民众赞成......