From 65f045957982f0be732b3ce2a43a3c4dfa0e2cf8 Mon Sep 17 00:00:00 2001 From: Eiichiro Adachi Date: Mon, 27 Jun 2022 12:44:36 +0900 Subject: [PATCH 1/2] fix: try to open with Chrome if default browser app does not support custom tabs --- .../chrome_custom_tabs/CustomTabsHelper.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/CustomTabsHelper.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/CustomTabsHelper.java index c3f0198d..ce707253 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/CustomTabsHelper.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/CustomTabsHelper.java @@ -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; @@ -59,7 +60,11 @@ public class CustomTabsHelper { } // Get all apps that can handle VIEW intents. - List resolvedActivityList = pm.queryIntentActivities(activityIntent, 0); + int flags = 0; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + flags |= PackageManager.MATCH_ALL; + } + List resolvedActivityList = pm.queryIntentActivities(activityIntent, flags); List packagesSupportingCustomTabs = new ArrayList<>(); for (ResolveInfo info : resolvedActivityList) { Intent serviceIntent = new Intent(); From 609ce9704abdd21b1fba68e1c2f4b0f27c68be5a Mon Sep 17 00:00:00 2001 From: Eiichiro Adachi Date: Mon, 27 Jun 2022 15:09:29 +0900 Subject: [PATCH 2/2] fix: set category to browser search intent to avoid unexpected query result --- .../chrome_custom_tabs/CustomTabsHelper.java | 1 + 1 file changed, 1 insertion(+) diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/CustomTabsHelper.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/CustomTabsHelper.java index ce707253..f49e3470 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/CustomTabsHelper.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/CustomTabsHelper.java @@ -53,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) {