Integrate CustomTabsHelper via Gradle
masterAdd the following dependency to your build.gradle file to include the CustomTabsHelper library in your Android project.
compile 'me.zhanghai.android.customtabshelper:library:1.0.6'repository·master·Indexed 18 days ago
https://github.com/zhanghai/customtabshelperAn Android utility library that simplifies Chrome Custom Tabs integration. It provides a CustomTabsHelperFragment to automatically manage the lifecycle of custom tab activities and includes functionality for pre-loading URLs via mayLaunchUrl and opening URIs with CustomTabsIntent.
Add the following dependency to your build.gradle file to include the CustomTabsHelper library in your Android project.
compile 'me.zhanghai.android.customtabshelper:library:1.0.6'Use mayLaunchUrl to hint to the system that a specific URL is likely to be opened soon. This allows the library to perform a 'warm up' boost. It is recommended to wrap this call in a CustomTabActivityHelper.ConnectionCallback to ensure the connection is ready.
mCustomTabsHelperFragment.mayLaunchUrl(YOUR_URI, null, null);To launch a URL using Chrome Custom Tabs, use the static open method on CustomTabsHelperFragment. You must provide the host context, a CustomTabsIntent, the target URI, and a fallback mechanism (such as an Intent to open the URL in a standard browser).
CustomTabsHelperFragment.open(this, mCustomTabsIntent, YOUR_URI, yourFallback);To manage the CustomTabActivityHelper lifecycle automatically, attach a CustomTabsHelperFragment to your activity. You can call CustomTabsHelperFragment.attachTo(this) within your activity's onCreate method. Because the fragment is always attached to the host activity, you can call attachTo() whenever a fragment or activity needs to use custom tabs, allowing for independent management of custom tabs usage.
private CustomTabsHelperFragment mCustomTabsHelperFragment;
...
@Override
protected void onCreate(Bundle savedInstanceState) {
...
mCustomTabsHelperFragment = CustomTabsHelperFragment.attachTo(this);
...
}