CustomTabsClient

public class CustomTabsClient
extends Object

java.lang.Object
   ↳ androidx.browser.customtabs.CustomTabsClient


Class to communicate with a CustomTabsService and create CustomTabsSession from it.

Summary

Public methods

static boolean bindCustomTabsService(Context context, String packageName, CustomTabsServiceConnection connection)

Bind to a CustomTabsService using the given package name and ServiceConnection.

static boolean bindCustomTabsServicePreservePriority(Context context, String packageName, CustomTabsServiceConnection connection)

Bind to a CustomTabsService using the given package name and ServiceConnection.

static boolean connectAndInitialize(Context context, String packageName)

Connects to the Custom Tabs warmup service, and initializes the browser.

Bundle extraCommand(String commandName, Bundle args)

Can be used as a channel between the Custom Tabs client and the provider to do something that is not part of the API yet.

static String getPackageName(Context context, List<String> packages)

Returns the preferred package to use for Custom Tabs, preferring the default VIEW handler.

static String getPackageName(Context context, List<String> packages, boolean ignoreDefault)

Returns the preferred package to use for Custom Tabs.

CustomTabsSession newSession(CustomTabsCallback callback)

Creates a new session through an ICustomTabsService with the optional callback.

CustomTabsSession newSession(CustomTabsCallback callback, int id)

Creates a new session or updates a callback for the existing session through an ICustomTabsService.

boolean warmup(long flags)

Warm up the browser process.

Inherited methods

Public methods

bindCustomTabsService

public static boolean bindCustomTabsService (Context context, 
                String packageName, 
                CustomTabsServiceConnection connection)

Bind to a CustomTabsService using the given package name and ServiceConnection.

Parameters
context Context: Context to use while calling Context.bindService(Intent, ServiceConnection, int)

packageName String: Package name to set on the Intent for binding.

connection CustomTabsServiceConnection: CustomTabsServiceConnection to use when binding. This will return a CustomTabsClient on #onCustomTabsServiceConnected(ComponentName, CustomTabsClient)

Returns
boolean Whether the binding was successful.

bindCustomTabsServicePreservePriority

public static boolean bindCustomTabsServicePreservePriority (Context context, 
                String packageName, 
                CustomTabsServiceConnection connection)

Bind to a CustomTabsService using the given package name and ServiceConnection. This is similar to bindCustomTabsService(Context, String, CustomTabsServiceConnection) but does not use Context.BIND_WAIVE_PRIORITY, making it suitable for use cases where the browser is immediately going to be launched and breaking the connection would be unrecoverable.

Parameters
context Context: Context to use while calling Context.bindService(Intent, ServiceConnection, int)

packageName String: Package name to set on the Intent for binding.

connection CustomTabsServiceConnection: CustomTabsServiceConnection to use when binding. This will return a CustomTabsClient on #onCustomTabsServiceConnected(ComponentName, CustomTabsClient)

Returns
boolean Whether the binding was successful.

connectAndInitialize

public static boolean connectAndInitialize (Context context, 
                String packageName)

Connects to the Custom Tabs warmup service, and initializes the browser. This convenience method connects to the service, and immediately warms up the Custom Tabs implementation. Since service connection is asynchronous, the return code is not the return code of warmup. This call is optional, and clients are encouraged to connect to the service, call warmup() and create a session. In this case, calling this method is not necessary.

Parameters
context Context: Context to use to connect to the remote service.

packageName String