CustomTabsClient
class CustomTabsClient
Class to communicate with a CustomTabsService and create CustomTabsSession from it.
Summary
Public functions |
|
|---|---|
AuthTabSession? |
Associate |
CustomTabsSession? |
Associate |
java-static Boolean |
bindCustomTabsService(Bind to a |
java-static Boolean |
bindCustomTabsServicePreservePriority(Bind to a |
java-static Boolean |
connectAndInitialize(context: Context, packageName: String)Connects to the Custom Tabs warmup service, and initializes the browser. |
java-static AuthTabSession.PendingSession |
@ExperimentalPendingSessionCreates a new pending session without a callback. |
java-static AuthTabSession.PendingSession |
@ExperimentalPendingSessionCreates a new pending session with a callback. |
Bundle? |
extraCommand(commandName: String, 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. |
java-static String? |
getPackageName(context: Context, packages: (Mutable)List<String!>?)Returns the preferred package to use for Custom Tabs, preferring the default VIEW handler. |
java-static String? |
Returns the preferred package to use for Custom Tabs. |
java-static Boolean |
isAuthTabSupported(context: Context, provider: String)Checks whether the Custom Tabs provider supports Auth Tab. |
java-static Boolean |
isEphemeralBrowsingSupported(context: Context, provider: String)Checks whether the Custom Tabs provider supports Ephemeral Browsing. |
java-static Boolean |
isSetNetworkSupported(context: Context, provider: String)Check whether the Custom Tabs provider supports multi-network feature |
AuthTabSession? |
newAuthTabSession(callback: AuthTabCallback?, executor: Executor?)Creates a new session through an ICustomTabsService with the optional callback. |
AuthTabSession? |
newAuthTabSession(callback: AuthTabCallback?, executor: Executor?, id: Int)Creates a new session through an ICustomTabsService with the optional callback. |
java-static CustomTabsSession.PendingSession |
newPendingSession(context: Context, callback: CustomTabsCallback?, id: Int)Creates a new pending session with an optional callback. |
CustomTabsSession? |
newSession(callback: CustomTabsCallback?)Creates a new session through an ICustomTabsService with the optional callback. |
CustomTabsSession? |
newSession(callback: CustomTabsCallback?, id: Int)Creates a new session or updates a callback for the existing session through an ICustomTabsService. |
Boolean |
Warm up the browser process. |
Public functions
attachAuthTabSession
@ExperimentalPendingSession
fun attachAuthTabSession(session: AuthTabSession.PendingSession): AuthTabSession?
Associate AuthTabSession.PendingSession with the service and turn it into an AuthTabSession.
| Parameters | |
|---|---|
session: AuthTabSession.PendingSession |
The |
| Returns | |
|---|---|
AuthTabSession? |
The |
attachSession
fun attachSession(session: CustomTabsSession.PendingSession): CustomTabsSession?
Associate CustomTabsSession.PendingSession with the service and turn it into a CustomTabsSession.
bindCustomTabsService
java-static fun bindCustomTabsService(
context: Context,
packageName: String,
connection: CustomTabsServiceConnection
): Boolean
Bind to a CustomTabsService using the given package name and ServiceConnection.
| Parameters | |
|---|---|
context: Context |
|
packageName: String |
Package name to set on the |
connection: CustomTabsServiceConnection |
|
| Returns | |
|---|---|
Boolean |
Whether the binding was successful. |
bindCustomTabsServicePreservePriority
java-static fun bindCustomTabsServicePreservePriority(
context: Context,
packageName: String,
connection: CustomTabsServiceConnection
): Boolean
Bind to a CustomTabsService using the given package name and ServiceConnection. This is similar to bindCustomTabsService but does not use 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 |
|
packageName: String |
Package name to set on the |
connection: CustomTabsServiceConnection |
|
| Returns | |
|---|---|
Boolean |
Whether the binding was successful. |
connectAndInitialize
java-static fun connectAndInitialize(context: Context, 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 |
|
packageName: String |
Package name of the target implementation. |
| Returns | |
|---|---|
Boolean |
Whether the binding was successful. |
createPendingAuthTabSession
@ExperimentalPendingSession
java-static fun createPendingAuthTabSession(context: Context, id: Int): AuthTabSession.PendingSession
Creates a new pending session without a callback. This session can be converted to a standard session using attachSession after connection.
| Returns | |
|---|---|
AuthTabSession.PendingSession |
The newly created |
createPendingAuthTabSession
@ExperimentalPendingSession
java-static fun createPendingAuthTabSession(
context: Context,
id: Int,
executor: Executor,
callback: AuthTabCallback
): AuthTabSession.PendingSession
Creates a new pending session with a callback. This session can be converted to a standard session using attachSession after connection.
| Parameters | |
|---|---|
context: Context |
The |
id: Int |
The session id. |
executor: Executor |
The |
callback: AuthTabCallback |
The callback through which the client will receive updates about the created session. |
| Returns | |
|---|---|
AuthTabSession.PendingSession |
The newly created |
extraCommand
fun extraCommand(commandName: String, 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
java-static fun getPackageName(context: Context, packages: (Mutable)List<String!>?): String?
Returns the preferred package to use for Custom Tabs, preferring the default VIEW handler.
getPackageName
java-static fun getPackageName(
context: Context,
packages: (Mutable)List<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. This method queries the PackageManager to determine which packages support the Custom Tabs API. On apps that target Android 11 and above, this requires adding the following package visibility elements to your manifest.
<!-- Place inside the <queries> element. --> <intent> <action android:name="android.support.customtabs.action.CustomTabsService" /> </intent>
| Parameters | |
|---|---|
context: Context |
|
packages: (Mutable)List<String!>? |
Ordered list of packages to test for Custom Tabs support, in decreasing order of priority. |
ignoreDefault: Boolean |
If set, the default VIEW handler won't get priority over other browsers. |
| Returns | |
|---|---|
String? |
The preferred package name for handling Custom Tabs, or |
isAuthTabSupported
java-static fun isAuthTabSupported(context: Context, provider: String): Boolean
Checks whether the Custom Tabs provider supports Auth Tab. See AuthTabIntent for more information on how to launch an Auth Tab.
| Parameters | |
|---|---|
context: Context |
The application |
provider: String |
The package name of the Custom Tabs provider. |
| Returns | |
|---|---|
Boolean |
Whether the Custom Tabs provider supports Auth Tab. |
| See also | |
|---|---|
CATEGORY_AUTH_TAB |
isEphemeralBrowsingSupported
java-static fun isEphemeralBrowsingSupported(context: Context, provider: String): Boolean
Checks whether the Custom Tabs provider supports Ephemeral Browsing.
| Parameters | |
|---|---|
context: Context |
The application |
provider: String |
The package name of the Custom Tabs provider. |
| Returns | |
|---|---|
Boolean |
Whether the Custom Tabs provider supports Ephemeral Browsing. |
| See also | |
|---|---|
CATEGORY_EPHEMERAL_BROWSING |
isSetNetworkSupported
java-static fun isSetNetworkSupported(context: Context, provider: String): Boolean
Check whether the Custom Tabs provider supports multi-network feature setNetwork, i.e. be able to bind a custom tab to a particular network.
| Parameters | |
|---|---|
context: Context |
Application context. |
provider: String |
the package name of Custom Tabs provider. |
| Returns | |
|---|---|
Boolean |
whether a Custom Tabs provider supports multi-network feature. |
| See also | |
|---|---|
setNetwork |
and CustomTabsService#CATEGORY_SET_NETWORK. |
newAuthTabSession
fun newAuthTabSession(callback: AuthTabCallback?, executor: Executor?): AuthTabSession?
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: AuthTabCallback? |
The callback through which the client will receive updates about the created session. Can be null. |
executor: Executor? |
The |
| Returns | |
|---|---|
AuthTabSession? |
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). |
newAuthTabSession
fun newAuthTabSession(callback: AuthTabCallback?, executor: Executor?, id: Int): AuthTabSession?
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: AuthTabCallback? |
The callback through which the client will receive updates about the created session. Can be null. |
executor: Executor? |
The |
id: Int |
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 Auth Tab instead of launching a new one. |
| Returns | |
|---|---|
AuthTabSession? |
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). |
newPendingSession
java-static fun newPendingSession(context: Context, callback: CustomTabsCallback?, id: Int): CustomTabsSession.PendingSession
Creates a new pending session with an optional callback. This session can be converted to a standard session using attachSession after connection. {@see PendingSession}
newSession
fun newSession(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. |
| Returns | |
|---|---|
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
fun newSession(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: Int |
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. |
| Returns | |
|---|---|
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 |
warmup
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. |
| Returns | |
|---|---|
Boolean |
Whether the warmup was successful. |