I have used following code for Facebook authentication and it is working fine, but when I have cancelled the authentication and tried to authenticate again the app crashed and the log was Caused by: java.lang.UnsupportedOperationException: Session: an attempt was made to open an already opened session.
On debug I got like this
{Session state:CREATED, token:{AccessToken token:ACCESS_TOKEN_REMOVED permissions:[]}, appId:xxxxxxxxxxxxxxx}
How can I solve this issue.Please help me.Thanks in advance
private void askFacebbokAuthentication() {
Session session = Session.getActiveSession();
if (session.isOpened()) {
facebook = true;
if (!hasPublishPermission()) {
session.requestNewPublishPermissions(new NewPermissionsRequest(
MyActivity.this, PERMISSIONS));
}
} else {
Session.OpenRequest openRequest = null;
openRequest = new Session.OpenRequest(MyActivity.this);
if (openRequest != null) {
openRequest.setDefaultAudience(SessionDefaultAudience.FRIENDS);
if (!hasPublishPermission()) {
openRequest.setPermissions(PERMISSIONS);
}
session.openForPublish(openRequest);
}
}
}