CustomTabsClient

open class CustomTabsClient
kotlin.Any
   ↳ androidx.browser.customtabs.CustomTabsClient

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

Summary

Public methods

open static Boolean
bindCustomTabsService(@NonNull context: Context, @Nullable packageName: String?, @NonNull connection: CustomTabsServiceConnection)

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

open static Boolean
connectAndInitialize(@NonNull context: Context, @NonNull packageName: String)

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

open Bundle?
extraCommand(@NonNull commandName: String, @Nullable args: Bundle?)

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.

open static String?
getPackageName(@NonNull context: Context, @Nullable packages: MutableList<String!>?)

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

open static String?
getPackageName(@NonNull context: Context, @Nullable packages: MutableList<String!>?, ignoreDefault: Boolean)

Returns the preferred package to use for Custom Tabs.

open CustomTabsSession?
newSession(@Nullable callback: CustomTabsCallback?)

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

open CustomTabsSession?
newSession(@Nullable callback: CustomTabsCallback?, id: Int)

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

open Boolean
warmup(flags: Long)

Warm up the browser process.

Public methods

bindCustomTabsService

open static fun bindCustomTabsService(@NonNull context: Context, @Nullable packageName: String?, @NonNull connection: CustomTabsServiceConnection): Boolean

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 Context: Package name to set on the Intent for binding.
connection Context: CustomTabsServiceConnection to use when binding. This will return a CustomTabsClient on #onCustomTabsServiceConnected(ComponentName, CustomTabsClient)
Return
Boolean: Whether the binding was successful.

connectAndInitialize

open static fun connectAndInitialize(@NonNull context: Context, @NonNull packageName: String): Boolean

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 Context: Package name of the target implementation.
Return
Boolean: Whether the binding was successful.

extraCommand

@Nullable open fun extraCommand(@NonNull commandName: String, @Nullable args: Bundle?): Bundle?

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.

getPackageName

@Nullable open static fun getPackageName(@NonNull context: Context, @Nullable packages: MutableList<String!>?): String?

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

getPackageName

@Nullable open static fun getPackageName(@NonNull context: Context, @Nullable packages: MutableList<String!>?, ignoreDefault: Boolean): String?

Returns the preferred package to use for Custom Tabs. The preferred package name is the default VIEW intent handler as long as it supports Custom Tabs. To modify this preferred behavior, set ignoreDefault to true and give a non empty list of package names in packages.

Parameters
context Context: Context to use for querying the packages.
packages Context: Ordered list of packages to test for Custom Tabs support, in decreasing order of priority.
ignoreDefault Context: If set, the default VIEW handler won't get priority over other browsers.
Return
String?: The preferred package name for handling Custom Tabs, or null.

newSession

@Nullable open fun newSession(@Nullable callback: CustomTabsCallback?): CustomTabsSession?

Creates a new session through an ICustomTabsService with the optional callback. This session can be used to associate any related communication through the service with an intent and then later with a Custom Tab. The client can then send later service calls or intents to through same session-intent-Custom Tab association.

Parameters
callback CustomTabsCallback?: The callback through which the client will receive updates about the created session. Can be null. All the callbacks will be received on the UI thread.
Return
CustomTabsSession?: The session object that was created as a result of the transaction. The client can use this to relay session specific calls. Null if the service failed to respond (threw a RemoteException).

newSession

@Nullable open fun newSession(@Nullable callback: CustomTabsCallback?, id: Int): CustomTabsSession?

Creates a new session or updates a callback for the existing session through an ICustomTabsService. This session can be used to associate any related communication through the service with an intent and then later with a Custom Tab. The client can then send later service calls or intents to through same session-intent-Custom Tab association.

Parameters
callback CustomTabsCallback?: The callback through which the client will receive updates about the created session. Can be null. All the callbacks will be received on the UI thread.
id CustomTabsCallback?: The session id. If the session with the specified id already exists for the given client application, the new callback is supplied to that session and further attempts to launch URLs using that session will update the existing Custom Tab instead of launching a new one.
Return
CustomTabsSession?: The session object that was created as a result of the transaction. The client can use this to relay session specific calls. Null if the service failed to respond (threw a RemoteException). If null is returned, attempt using newSession(CustomTabsCallback) which is supported with older browsers.

warmup

open fun warmup(flags: Long): Boolean

Warm up the browser process. Allows the browser application to pre-initialize itself in the background. Significantly speeds up URL opening in the browser. This is asynchronous and can be called several times.

Parameters
flags Long: Reserved for future use.
Return
Boolean: Whether the warmup was successful.