When I'm using Facebook login in an Android app, the callback is called before the permissions popup is shown. In my code, the expected behaviour should be:
- User opens app
- User clicks "sign in" button
- FB permissions dialog pops up
- User accepts FB permissions
- A "hi there!" toast message is shown
However, the actual flow is:
- User opens app
- User clicks "sign in" button
- A "hi there!" toast message is shown
- FB permissions dialog pops up
I basically used the code from this answer and added a button to perform the login when the user clicks on it, instead of on activity creation:
public class MainActivity extends Activity implements StatusCallback {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void signIn(View view) {
OpenRequest open = new OpenRequest(this);
open.setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO);
open.setPermissions(Arrays.asList(new String[] { "email", "user_hometown" }));
open.setCallback(this);
Session s = new Session(this);
s.openForRead(open);
}
@Override
public void call(Session session, SessionState state, Exception exception) {
CharSequence text = "Hi there!";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(getApplicationContext(), text, duration);
toast.show();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (Session.getActiveSession() != null)
Session.getActiveSession().onActivityResult(this, requestCode,
resultCode, data);
}
}
Thanks