fix: chrome tab open failed due to chrome process not running
This commit is contained in:
parent
b00b3781ef
commit
4c712b6f36
|
@ -165,8 +165,16 @@ public class ChromeCustomTabsActivity extends Activity implements Disposable {
|
||||||
@Nullable Map<String, String> headers,
|
@Nullable Map<String, String> headers,
|
||||||
@Nullable String referrer,
|
@Nullable String referrer,
|
||||||
@Nullable List<String> otherLikelyURLs) {
|
@Nullable List<String> otherLikelyURLs) {
|
||||||
|
launchUrlWithSession(customTabsSession, url, headers, referrer, otherLikelyURLs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void launchUrlWithSession(@Nullable CustomTabsSession session,
|
||||||
|
@NonNull String url,
|
||||||
|
@Nullable Map<String, String> headers,
|
||||||
|
@Nullable String referrer,
|
||||||
|
@Nullable List<String> otherLikelyURLs) {
|
||||||
mayLaunchUrl(url, otherLikelyURLs);
|
mayLaunchUrl(url, otherLikelyURLs);
|
||||||
builder = new CustomTabsIntent.Builder(customTabsSession);
|
builder = new CustomTabsIntent.Builder(session);
|
||||||
prepareCustomTabs();
|
prepareCustomTabs();
|
||||||
|
|
||||||
CustomTabsIntent customTabsIntent = builder.build();
|
CustomTabsIntent customTabsIntent = builder.build();
|
||||||
|
@ -328,7 +336,17 @@ public class ChromeCustomTabsActivity extends Activity implements Disposable {
|
||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
super.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
|
@Override
|
||||||
|
|
|
@ -122,14 +122,14 @@ public class CustomTabActivityHelper implements ServiceConnectionCallback {
|
||||||
* Binds the Activity to the Custom Tabs Service.
|
* Binds the Activity to the Custom Tabs Service.
|
||||||
* @param activity the activity to be binded to the service.
|
* @param activity the activity to be binded to the service.
|
||||||
*/
|
*/
|
||||||
public void bindCustomTabsService(Activity activity) {
|
public boolean bindCustomTabsService(Activity activity) {
|
||||||
if (mClient != null) return;
|
if (mClient != null) return true;
|
||||||
|
|
||||||
String packageName = CustomTabsHelper.getPackageNameToUse(activity);
|
String packageName = CustomTabsHelper.getPackageNameToUse(activity);
|
||||||
if (packageName == null) return;
|
if (packageName == null) return false;
|
||||||
|
|
||||||
mConnection = new ServiceConnection(this);
|
mConnection = new ServiceConnection(this);
|
||||||
CustomTabsClient.bindCustomTabsService(activity, packageName, mConnection);
|
return CustomTabsClient.bindCustomTabsService(activity, packageName, mConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue