diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/ChromeCustomTabsActivity.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/ChromeCustomTabsActivity.java index 84afb575..8ba4efce 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/ChromeCustomTabsActivity.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/ChromeCustomTabsActivity.java @@ -165,8 +165,16 @@ public class ChromeCustomTabsActivity extends Activity implements Disposable { @Nullable Map headers, @Nullable String referrer, @Nullable List otherLikelyURLs) { + launchUrlWithSession(customTabsSession, url, headers, referrer, otherLikelyURLs); + } + + public void launchUrlWithSession(@Nullable CustomTabsSession session, + @NonNull String url, + @Nullable Map headers, + @Nullable String referrer, + @Nullable List otherLikelyURLs) { mayLaunchUrl(url, otherLikelyURLs); - builder = new CustomTabsIntent.Builder(customTabsSession); + builder = new CustomTabsIntent.Builder(session); prepareCustomTabs(); CustomTabsIntent customTabsIntent = builder.build(); @@ -328,7 +336,17 @@ public class ChromeCustomTabsActivity extends Activity implements Disposable { @Override protected void onStart() { super.onStart(); - customTabActivityHelper.bindCustomTabsService(this); + boolean isBindSuccess = customTabActivityHelper.bindCustomTabsService(this); + + if (!isBindSuccess) { + // chrome process not running, start tab directly + + if (initialUrl != null) { + launchUrlWithSession(null, initialUrl, initialHeaders, initialReferrer, initialOtherLikelyURLs); + //avoid webpage reopen: onServiceConnected->launchUrl + initialUrl = null; + } + } } @Override diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/CustomTabActivityHelper.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/CustomTabActivityHelper.java index 10d930eb..75964cc6 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/CustomTabActivityHelper.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/CustomTabActivityHelper.java @@ -122,14 +122,14 @@ public class CustomTabActivityHelper implements ServiceConnectionCallback { * Binds the Activity to the Custom Tabs Service. * @param activity the activity to be binded to the service. */ - public void bindCustomTabsService(Activity activity) { - if (mClient != null) return; + public boolean bindCustomTabsService(Activity activity) { + if (mClient != null) return true; String packageName = CustomTabsHelper.getPackageNameToUse(activity); - if (packageName == null) return; + if (packageName == null) return false; mConnection = new ServiceConnection(this); - CustomTabsClient.bindCustomTabsService(activity, packageName, mConnection); + return CustomTabsClient.bindCustomTabsService(activity, packageName, mConnection); } /**