I am trying to be able to handle this situation:
- User presses Login with Facebook:
- User presses Cancel in the Facebook Login page;
- User presses Login with Facebook again;
The problem I have is that I can't feed the application id as a resource, so instead I use this to create the facebook session:
mFacebookSession = Session.getActiveSession();
if (mFacebookSession == null)
{
mFacebookSession = new Session.Builder(m_activity).setApplicationId(fbAppId).build();
Session.setActiveSession(mFacebookSession);
mFacebookStatusCallback = new FacebookStatusCallback(mFacebookSession, mFacebookWrapper);
}
To open the session, I use this:
if (!mFacebookSession.isOpened() && !mFacebookSession.isClosed())
{
Session.OpenRequest openRequest = new Session.OpenRequest(mActivity).setCallback(mFacebookStatusCallback);
openRequest.setPermissions(Arrays.asList("user_birthday", "email"));
mFacebookSession.openForPublish(openRequest); //tried with openForRead too
}
else
{
Session.openActiveSession(mActivity, true, Arrays.asList("user_birthday", "email"), mFacebookStatusCallback);
}
Everything should be fine, but because I don't feed the facebook app id in the resources, I get this :
02-27 14:53:55.011: E/AndroidRuntime(17294): java.lang.NullPointerException: Argument 'applicationId' cannot be null
02-27 14:53:55.011: E/AndroidRuntime(17294): at com.facebook.internal.Validate.notNull(Validate.java:29)
02-27 14:53:55.011: E/AndroidRuntime(17294): at com.facebook.Session.<init>(Session.java:281)
02-27 14:53:55.011: E/AndroidRuntime(17294): at com.facebook.Session.<init>(Session.java:270)
02-27 14:53:55.011: E/AndroidRuntime(17294): at com.facebook.Session$Builder.build(Session.java:1822)
02-27 14:53:55.011: E/AndroidRuntime(17294): at com.facebook.Session.openActiveSession(Session.java:1130)
02-27 14:53:55.011: E/AndroidRuntime(17294): at com.facebook.Session.openActiveSession(Session.java:1041)
I need to mention that the exception is thrown at step 3 (second login attempt). Trying to login the first time works. Can anyone tell me how I could feed the applicationId so that I don't get that error when trying to open the active session? Should I do anything special when handling the canceled exception? I am currently showing a toast that the operation was canceled.
Because I was asked to post the manifest, I will mention that I have the facebook activity in it:
<activity
android:name="com.facebook.LoginActivity"
android:label="@string/app_name" >
</activity>