Android Facebook SDK 3.0 auth

自作多情 提交于 2019-11-30 09:38:34
Giulio Piancastelli

I ran into the same problem, except that in my case the offending requestCode was 326350 (0x4face). And I was indeed calling super.onActivityResult, so the workaround proposed by Eric Savage was already in place but not effective. Weirdest thing of all, this stuff did work just a couple of weeks ago, and the offending behaviour appeared without myself upgrading anything (Facebook SDK version, Android version, support library version, even the phone on which I'm developing/testing, are all the same as when I had it working).

However, Eric's answer contains other interesting hints, which I exploited to make my code work again. Basically, instead of passing the whole requestCode to Session.onActivityResult, I cut the lowest 16 bits and pass those only.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Session session = Session.getActiveSession();
    int sanitizedRequestCode = requestCode % 0x10000;
    session.onActivityResult(this, sanitizedRequestCode, resultCode, data);
}

I do believe this is a bug that should be fixed in the Facebook SDK, and would insist to have it patched for the next release.

Just ran into this same issue. The difference between 64206 (0xface) and 129742 (0x1face) is because FragmentActivity has tacked on an extra 0x10000 to determine which fragment it came from. This was resolved by making sure the super activity was called during onActivityResult

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    switch (requestCode) {
        // ...
    }
}

You "Can only use lower 16 bits for requestCode", as stated in FragmentActivity.startActivityFromFragment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!