CustomTabsHelper Documentation

repository·master·Indexed 18 days ago

https://github.com/zhanghai/customtabshelper

An 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.

Tokens
505
Snippets
4
Records
4
Agent score
14%

What's inside CustomTabsHelper

  1. Hint a likely URL for pre-loading

    master

    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);
  2. Open a URL with Custom Tabs

    master

    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);
  3. Attach CustomTabsHelperFragment to an Activity

    master

    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);
        ...
    }