diff options
author | Alex Ning <chineseperson5@gmail.com> | 2019-10-06 01:11:13 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2019-10-06 01:11:13 +0000 |
commit | 2a2270155d447a9a0412c172f85e74260b25306f (patch) | |
tree | 928bc929f0580f57c14965c3376b1ea05e2cc329 /app/src/main/java/ml | |
parent | b56594aeba17afb0a938188082fcc91679826b55 (diff) | |
download | infinity-for-reddit-2a2270155d447a9a0412c172f85e74260b25306f.tar infinity-for-reddit-2a2270155d447a9a0412c172f85e74260b25306f.tar.gz infinity-for-reddit-2a2270155d447a9a0412c172f85e74260b25306f.tar.bz2 infinity-for-reddit-2a2270155d447a9a0412c172f85e74260b25306f.tar.lz infinity-for-reddit-2a2270155d447a9a0412c172f85e74260b25306f.tar.xz infinity-for-reddit-2a2270155d447a9a0412c172f85e74260b25306f.tar.zst infinity-for-reddit-2a2270155d447a9a0412c172f85e74260b25306f.zip |
Open browser first instead of Chrome Custom Tabs when opening links.
Diffstat (limited to 'app/src/main/java/ml')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java | 60 |
1 files changed, 30 insertions, 30 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java index a95c4f96..c35a8073 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java @@ -149,25 +149,30 @@ public class LinkResolverActivity extends AppCompatActivity { } private void deepLinkError(Uri uri) { + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setData(uri); + PackageManager pm = getPackageManager(); - ArrayList<ResolveInfo> resolveInfos = getCustomTabsPackages(pm); - if (!resolveInfos.isEmpty()) { - CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); - // add share action to menu list - builder.addDefaultShareMenuItem(); - builder.setToolbarColor(getResources().getColor(R.color.colorPrimary)); - CustomTabsIntent customTabsIntent = builder.build(); - customTabsIntent.intent.setPackage(resolveInfos.get(0).activityInfo.packageName); - if (uri.getScheme() == null) { - uri = Uri.parse("http://" + uri.toString()); + List<ResolveInfo> activities = pm.queryIntentActivities(intent, 0); + ArrayList<String> packageNames = new ArrayList<>(); + + String currentPackageName = getApplicationContext().getPackageName(); + + for (ResolveInfo info : activities) { + if (!info.activityInfo.packageName.equals(currentPackageName)) { + packageNames.add(info.activityInfo.packageName); } + } + + if (!packageNames.isEmpty()) { + intent.setPackage(packageNames.get(0)); try { - customTabsIntent.launchUrl(this, uri); + startActivity(intent); } catch (ActivityNotFoundException e) { - openInBrowser(uri, pm); + openInCustomTabs(uri, pm); } } else { - openInBrowser(uri, pm); + openInCustomTabs(uri, pm); } } @@ -190,25 +195,20 @@ public class LinkResolverActivity extends AppCompatActivity { return packagesSupportingCustomTabs; } - private void openInBrowser(Uri uri, PackageManager pm) { - Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(uri); - - List<ResolveInfo> activities = pm.queryIntentActivities(intent, 0); - ArrayList<String> packageNames = new ArrayList<>(); - - String currentPackageName = getApplicationContext().getPackageName(); - - for (ResolveInfo info : activities) { - if (!info.activityInfo.packageName.equals(currentPackageName)) { - packageNames.add(info.activityInfo.packageName); + private void openInCustomTabs(Uri uri, PackageManager pm) { + ArrayList<ResolveInfo> resolveInfos = getCustomTabsPackages(pm); + if (!resolveInfos.isEmpty()) { + CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); + // add share action to menu list + builder.addDefaultShareMenuItem(); + builder.setToolbarColor(getResources().getColor(R.color.colorPrimary)); + CustomTabsIntent customTabsIntent = builder.build(); + customTabsIntent.intent.setPackage(resolveInfos.get(0).activityInfo.packageName); + if (uri.getScheme() == null) { + uri = Uri.parse("http://" + uri.toString()); } - } - - if (!packageNames.isEmpty()) { - intent.setPackage(packageNames.get(0)); try { - startActivity(intent); + customTabsIntent.launchUrl(this, uri); } catch (ActivityNotFoundException e) { Toast.makeText(this, R.string.no_browser_found, Toast.LENGTH_SHORT).show(); } |