AppAuth-Android icon indicating copy to clipboard operation
AppAuth-Android copied to clipboard

ActivityNotFoundException on Samsung device

Open gaurav115 opened this issue 9 years ago • 5 comments

When I try to run the sample code on a Samsung device ( in this case Samsung Galaxy S5 ), the line

mAuthService.performAuthorizationRequest( authRequest, pendingIntent, mAuthService.createCustomTabsIntentBuilder() .setToolbarColor(getColorCompat(R.color.colorPrimary)) .build());

results in Activity Not found Exception.

The logcat is mentioned below:

              java.lang.RuntimeException: Unable to start activity ComponentInfo{com.netzwelt.emailclient/com.netzwelt.emailclient.EmailSetUp.ActivityGoogleOauth}: android.content.ActivityNotFoundException
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3253)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
                  at android.app.ActivityThread.access$1100(ActivityThread.java:221)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
                  at android.os.Handler.dispatchMessage(Handler.java:102)
                  at android.os.Looper.loop(Looper.java:158)
                  at android.app.ActivityThread.main(ActivityThread.java:7224)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
               Caused by: android.content.ActivityNotFoundException
                  at net.openid.appauth.AuthorizationService.performAuthorizationRequest(AuthorizationService.java:209)
                  at net.openid.appauth.AuthorizationService.performAuthorizationRequest(AuthorizationService.java:132)
                  at com.netzwelt.emailclient.EmailSetUp.ActivityGoogleOauth.requestAuth(ActivityGoogleOauth.java:150)
                  at com.netzwelt.emailclient.EmailSetUp.ActivityGoogleOauth.onCreate(ActivityGoogleOauth.java:83)
                  at android.app.Activity.performCreate(Activity.java:6876)
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349) 
                  at android.app.ActivityThread.access$1100(ActivityThread.java:221) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794) 
                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                  at android.os.Looper.loop(Looper.java:158) 
                  at android.app.ActivityThread.main(ActivityThread.java:7224) 
                  at java.lang.reflect.Method.invoke(Native Method) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120

This seems to be an issue with Samsung device where Chrome ain't the default browser, the same code ran fine on a Nexus 5.

Even the demo / sample app present under this repository crashes with the same exception on Samsung S5 ( while runs fine on a Nexus 5 ).

gaurav115 avatar Jan 10 '17 10:01 gaurav115

Can you confirm whether any browsers are recognized by the library, by setting a breakpoint here:

https://github.com/openid/AppAuth-Android/blob/master/library/java/net/openid/appauth/browser/BrowserSelector.java#L123

What browsers are installed on your test device?

iainmcgin avatar Jan 17 '17 22:01 iainmcgin

I ran the method " getAllBrowsers(Context) " as you suggested (in my test code, I just took the desired method and ran in a project), in the result I get a list containing 4 objects, two of them have the package name "com.sec.android.app.sbrowser" and the other two "com.android.chrome".

The device has the Samsung "SBrowser" and "Chrome" installed in it.

gaurav115 avatar Jan 18 '17 07:01 gaurav115

This actually is a little strange, now when I run the sample appAuth app and even my own app , I can see the list of browser under the browser selection spinner, while in the past I could not see any option ( which actually was the issue I posted ).

The only change I remember is that one of my team members had formatted the Samsung device a while ago. May be ( I am not entirely sure ) that had to do something with this ( as now it works and I have not changed anything in the code :) ).

So I guess it is better for me to close this for now.

gaurav115 avatar Jan 18 '17 07:01 gaurav115

This is mainly related to neither of the browser present or enabled among[chrome/safari/firefox] I added a check before performing request that browsers are present in my phone and they are enabeled, crash also happens when browser is present but it is disabled. Before calling library method

if (AndroidUtils. isAppEnabled(context, Browsers.Chrome.PACKAGE_NAME)
                    || AndroidUtils isAppEnabled context, Browsers.SBrowser.PACKAGE_NAME)
                    || AndroidUtils. isAppEnabled context, Browsers.Firefox.PACKAGE_NAME)) {
//proceed
}

Checking if app is installed

public static boolean isAppEnabled(@NonNull Context context, String packageName)
            throws PackageManager.NameNotFoundException {
        final ApplicationInfo ai =
               context.getPackageManager().getApplicationInfo(packageName, 0);
        return ai.enabled;
}

silentsudo avatar Dec 24 '18 08:12 silentsudo

To provide better accountability for access to installed apps on a device, apps targeting Android 11 (API level 30) will see a filtered list of installed apps by default. In order to access a broader list of installed apps, an app can specify information about apps they need to query and interact with directly. This can be done by adding a element in the Android manifest.

I am able to resolve it by adding <Manifest> .. <queries> <intent> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="https" /> </intent> </queries> </Manifest>

ShridharBanavasi1997 avatar Mar 25 '22 13:03 ShridharBanavasi1997