Created
July 1, 2020 16:05
Revisions
-
hborders created this gist
Jul 1, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ fun launchBrowser(context: Context, uri: Uri?) { val browserIntent = Intent(Intent.ACTION_VIEW).apply { data = uri } val browseActivities = context.packageManager.queryIntentActivities(browserIntent, PackageManager.MATCH_DEFAULT_ONLY) for (info in browseActivities) { if (info.activityInfo.packageName != context.packageName) { browserIntent.setPackage(info.activityInfo.packageName) try { context.startActivity(browserIntent) break } catch (e: ActivityNotFoundException) { // No-op, Activity unable to handle intent, try another } } } }