Cooltey has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/395902 )
Change subject: Fix an external link issue after setup "always" while opening deep links ...................................................................... Fix an external link issue after setup "always" while opening deep links - Add a method to get default brower app's package name (either Chrome or Browser) - Try one more time to open external link before showing error toast Bug: T181459 Change-Id: I28920a8790a86888e7dc1b89d94d7bbfd29ce015 --- M app/src/main/java/org/wikipedia/util/DeviceUtil.java M app/src/main/java/org/wikipedia/util/UriUtil.java 2 files changed, 35 insertions(+), 5 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia refs/changes/02/395902/1 diff --git a/app/src/main/java/org/wikipedia/util/DeviceUtil.java b/app/src/main/java/org/wikipedia/util/DeviceUtil.java index a6d3569..2a7f260 100644 --- a/app/src/main/java/org/wikipedia/util/DeviceUtil.java +++ b/app/src/main/java/org/wikipedia/util/DeviceUtil.java @@ -3,6 +3,7 @@ import android.app.Activity; import android.content.Context; import android.content.Intent; +import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.net.ConnectivityManager; import android.net.NetworkInfo; @@ -33,6 +34,24 @@ return resInfo.size() > 0; } + public static String getBrowserAppPackageName(Context context) { + PackageManager packageManager = context.getPackageManager(); + + // com.android.chrome => for device >= Android 7.0 + // com.android.browser => for device < Android 7.0 + String[] browserApps = {"com.android.chrome", "com.android.browser"}; + + for (String app : browserApps) { + try { + packageManager.getPackageInfo(app, 0); + return app; + } catch (Exception e) { + continue; + } + } + return null; + } + /** * Attempt to display the Android keyboard. * diff --git a/app/src/main/java/org/wikipedia/util/UriUtil.java b/app/src/main/java/org/wikipedia/util/UriUtil.java index f196172..5a970a2 100644 --- a/app/src/main/java/org/wikipedia/util/UriUtil.java +++ b/app/src/main/java/org/wikipedia/util/UriUtil.java @@ -63,12 +63,23 @@ * @param uri URI to open in an external browser */ public static void visitInExternalBrowser(final Context context, Uri uri) { - Intent chooserIntent = ShareUtil.createChooserIntent(new Intent(Intent.ACTION_VIEW, uri), - null, context); + + Intent intent = new Intent(Intent.ACTION_VIEW, uri); + Intent chooserIntent = ShareUtil.createChooserIntent(intent, null, context); + if (chooserIntent == null) { - // This means that there was no way to handle this link. - // We will just show a toast now. FIXME: Make this more visible? - ShareUtil.showUnresolvableIntentMessage(context); + String browserPackageName = DeviceUtil.getBrowserAppPackageName(context); + if (browserPackageName != null) { + // Try to to open the external browser instead of showing error toast. + // TODO: update DeviceUtil.getBrowserAppPackageName() if Google changes their built-in browser app + intent.setPackage(browserPackageName); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(intent); + } else { + // This means that there was no way to handle this link. + // We will just show a toast now. FIXME: Make this more visible? + ShareUtil.showUnresolvableIntentMessage(context); + } } else { chooserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(chooserIntent); -- To view, visit https://gerrit.wikimedia.org/r/395902 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I28920a8790a86888e7dc1b89d94d7bbfd29ce015 Gerrit-PatchSet: 1 Gerrit-Project: apps/android/wikipedia Gerrit-Branch: master Gerrit-Owner: Cooltey <cf...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits