Merge pull request #1233 from initig/fix_no_custom_tab_default_browser

fix: try to open with Chrome if default browser app does not support custom tabs
This commit is contained in:
Lorenzo Pichilli 2022-10-13 16:36:15 +02:00 committed by GitHub
commit 89808a2f67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 1 deletions

View File

@ -6,6 +6,7 @@ import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Build;
import android.text.TextUtils;
import android.util.Log;
@ -52,6 +53,7 @@ public class CustomTabsHelper {
PackageManager pm = context.getPackageManager();
// Get default VIEW intent handler.
Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
activityIntent.addCategory(Intent.CATEGORY_BROWSABLE);
ResolveInfo defaultViewHandlerInfo = pm.resolveActivity(activityIntent, 0);
String defaultViewHandlerPackageName = null;
if (defaultViewHandlerInfo != null) {
@ -59,7 +61,11 @@ public class CustomTabsHelper {
}
// Get all apps that can handle VIEW intents.
List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent, 0);
int flags = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
flags |= PackageManager.MATCH_ALL;
}
List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent, flags);
List<String> packagesSupportingCustomTabs = new ArrayList<>();
for (ResolveInfo info : resolvedActivityList) {
Intent serviceIntent = new Intent();