0

I was using an old version of Facebook Android SDK (I think v 3.0.1) for quite a while until I got into a problem Loging In through Facebook.

I was getting this error in the Stack Trace:

java.lang.RuntimeException: Unable to resume activity {com.example/com.facebook.LoginActivity}: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.facebook.platform.PLATFORM_SERVICE cat=[android.intent.category.DEFAULT] }
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2958)
    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2989)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2372)
    at android.app.ActivityThread.access$800(ActivityThread.java:148)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5274)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:909)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:704)
Caused by: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.facebook.platform.PLATFORM_SERVICE cat=[android.intent.category.DEFAULT] }
    at android.app.ContextImpl.validateServiceIntent(ContextImpl.java:1745)
    at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1844)
    at android.app.ContextImpl.bindService(ContextImpl.java:1822)
    at android.content.ContextWrapper.bindService(ContextWrapper.java:538)
    at com.facebook.GetTokenClient.start(GetTokenClient.java:62)
    at com.facebook.AuthorizationClient$GetTokenAuthHandler.tryAuthorize(AuthorizationClient.java:535)
    at com.facebook.AuthorizationClient.tryCurrentHandler(AuthorizationClient.java:214)
    at com.facebook.AuthorizationClient.tryNextHandler(AuthorizationClient.java:193)
    at com.facebook.AuthorizationClient.authorize(AuthorizationClient.java:121)
    at com.facebook.AuthorizationClient.startOrContinueAuth(AuthorizationClient.java:102)
    at com.facebook.LoginActivity.onResume(LoginActivity.java:113)
    at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1241)
    at android.app.Activity.performResume(Activity.java:6063)
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2947)
    ... 11 more
java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.facebook.platform.PLATFORM_SERVICE cat=[android.intent.category.DEFAULT] }
    at android.app.ContextImpl.validateServiceIntent(ContextImpl.java:1745)
    at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1844)
    at android.app.ContextImpl.bindService(ContextImpl.java:1822)
    at android.content.ContextWrapper.bindService(ContextWrapper.java:538)
    at com.facebook.GetTokenClient.start(GetTokenClient.java:62)
    at com.facebook.AuthorizationClient$GetTokenAuthHandler.tryAuthorize(AuthorizationClient.java:535)
    at com.facebook.AuthorizationClient.tryCurrentHandler(AuthorizationClient.java:214)
    at com.facebook.AuthorizationClient.tryNextHandler(AuthorizationClient.java:193)
    at com.facebook.AuthorizationClient.authorize(AuthorizationClient.java:121)
    at com.facebook.AuthorizationClient.startOrContinueAuth(AuthorizationClient.java:102)
    at com.facebook.LoginActivity.onResume(LoginActivity.java:113)
    at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1241)
    at android.app.Activity.performResume(Activity.java:6063)
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2947)
    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2989)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2372)
    at android.app.ActivityThread.access$800(ActivityThread.java:148)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5274)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:909)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:704)

If I Login to Facebook through Android Lollipop Device that has Facebook Apps installed in it.

I currently avoiding this issue by changing the SessionLoginBehavior using this code currently

public void loginFacebook(){
    Session session = new Session(context);
    Session.setActiveSession(session);
    Session.OpenRequest openRequest = null;
    if (fragment != null) {
        openRequest = new Session.OpenRequest(fragment);
    } else if (context instanceof Activity) {
        openRequest = new Session.OpenRequest((Activity)context);
    }

    if (openRequest != null) {
        openRequest.setDefaultAudience(SessionDefaultAudience.FRIENDS);
        openRequest.setPermissions(Arrays.asList("email", "user_birthday"));
        //openRequest.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK);         //  Native Login Changed
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {                    //  Lollipop force login from website
            openRequest.setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO);
        } else {                                                                        //  Below Lollipop login with fallback
            openRequest.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK);
        }

        session.openForRead(openRequest);
    }
}

If I changed the Facebook SDK to v. 4.1.1, I got a lot of error because a lot of the import from the Facebook SDK isn't there anymore int v 4.1.1

What should I do to fix this issue without changing the SessionLoginBehavior, should I just stay with the current fix implementation or else?

Kyojimaru
  • 2,694
  • 1
  • 14
  • 22
  • 1
    there is no `SessionLoginBehavior` anymore in sdk >4 Follow their documentation and re implement facebook login – Tse Ka Leong May 14 '15 at 06:14
  • 1
    The newest facebook SDK does not use the `Session` class. If you want to use the newest SDK, you have to handle the providen callbacks. Here is a [full example of the newest SDK](http://stackoverflow.com/questions/29605236/cant-get-location-and-email-using-facebook-api/29605975#29605975). – Menelaos Kotsollaris May 14 '15 at 06:14
  • @Try_me34 so it's either changing my custom button to `Facebook Login Button` and use the SDK v.4+, or change to the latest SDK v.3 and keep the current code? And do you have any idea about the crash log if I try to login on Lollipop device with Facebook apps installed on it? – Kyojimaru May 14 '15 at 15:36
  • 1
    I would highly suggest you update to the new SDK . At this moment, Lolipop is very buggy so I am assuming that they will fix it asap. I am not aware of any workaround atm. Keep in mind that if you stick with the older SDK you will most likely be in an uncomfortable position in the future (possibly cause of unsupportable SDK or so..) – Menelaos Kotsollaris May 14 '15 at 15:42

0 Answers0