Skip to content

Most visited

Recently visited

navigation

CustomTabsService

public abstract class CustomTabsService
extends Service

java.lang.Object
   ↳ android.content.Context
     ↳ android.content.ContextWrapper
       ↳ android.app.Service
         ↳ android.support.customtabs.CustomTabsService


Abstract service class for implementing Custom Tabs related functionality. The service should be responding to the action ACTION_CUSTOM_TABS_CONNECTION. This class should be used by implementers that want to provide Custom Tabs functionality, not by clients that want to launch Custom Tabs.

Summary

Nested classes

@interface CustomTabsService.Result

 

Constants

String ACTION_CUSTOM_TABS_CONNECTION

The Intent action that a CustomTabsService must respond to.

String KEY_URL

For mayLaunchUrl(CustomTabsSessionToken, Uri, Bundle, List) calls that wants to specify more than one url, this key can be used with putParcelable(String, android.os.Parcelable) to insert a new url to each bundle inside list of bundles.

int RESULT_FAILURE_DISALLOWED

Indicates that the postMessage request was not allowed due to a bad argument or requesting at a disallowed time like when in background.

int RESULT_FAILURE_MESSAGING_ERROR

Indicates that the postMessage request has failed due to an internal error on the browser message channel.

int RESULT_FAILURE_REMOTE_ERROR

Indicates that the postMessage request has failed due to a RemoteException .

int RESULT_SUCCESS

Indicates that the postMessage request was accepted.

Inherited constants

From class android.app.Service
From class android.content.Context
From interface android.content.ComponentCallbacks2

Public constructors

CustomTabsService()

Public methods

IBinder onBind(Intent intent)

Return the communication channel to the service.

Protected methods

boolean cleanUpSession(CustomTabsSessionToken sessionToken)

Called when the client side IBinder for this CustomTabsSessionToken is dead.

abstract Bundle extraCommand(String commandName, Bundle args)

Unsupported commands that may be provided by the implementation.

abstract boolean mayLaunchUrl(CustomTabsSessionToken sessionToken, Uri url, Bundle extras, List<Bundle> otherLikelyBundles)

Tells the browser of a likely future navigation to a URL.

abstract boolean newSession(CustomTabsSessionToken sessionToken)

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

abstract int postMessage(CustomTabsSessionToken sessionToken, String message, Bundle extras)

Sends a postMessage request using the origin communicated via requestPostMessageChannel(CustomTabsSessionToken, Uri).

abstract boolean requestPostMessageChannel(CustomTabsSessionToken sessionToken, Uri postMessageOrigin)

Sends a request to create a two way postMessage channel between the client and the browser linked with the given CustomTabsSession.

abstract boolean updateVisuals(CustomTabsSessionToken sessionToken, Bundle bundle)

Updates the visuals of custom tabs for the given session.

abstract boolean warmup(long flags)

Warms up the browser process asynchronously.

Inherited methods

From class android.app.Service
From class android.content.ContextWrapper
From class android.content.Context
From class java.lang.Object
From interface android.content.ComponentCallbacks2
From interface android.content.ComponentCallbacks

Constants

ACTION_CUSTOM_TABS_CONNECTION

added in version 23.0.0
String ACTION_CUSTOM_TABS_CONNECTION

The Intent action that a CustomTabsService must respond to.

Constant Value: "android.support.customtabs.action.CustomTabsService"

KEY_URL

added in version 23.0.0
String KEY_URL

For mayLaunchUrl(CustomTabsSessionToken, Uri, Bundle, List) calls that wants to specify more than one url, this key can be used with putParcelable(String, android.os.Parcelable) to insert a new url to each bundle inside list of bundles.

Constant Value: "android.support.customtabs.otherurls.URL"

RESULT_FAILURE_DISALLOWED

added in version 25.3.0
int RESULT_FAILURE_DISALLOWED

Indicates that the postMessage request was not allowed due to a bad argument or requesting at a disallowed time like when in background.

Constant Value: -1 (0xffffffff)

RESULT_FAILURE_MESSAGING_ERROR

added in version 25.3.0
int RESULT_FAILURE_MESSAGING_ERROR

Indicates that the postMessage request has failed due to an internal error on the browser message channel.

Constant Value: -3 (0xfffffffd)

RESULT_FAILURE_REMOTE_ERROR

added in version 25.3.0
int RESULT_FAILURE_REMOTE_ERROR

Indicates that the postMessage request has failed due to a RemoteException .

Constant Value: -2 (0xfffffffe)

RESULT_SUCCESS

added in version 25.3.0
int RESULT_SUCCESS

Indicates that the postMessage request was accepted.

Constant Value: 0 (0x00000000)

Public constructors

CustomTabsService

added in version 23.0.0
CustomTabsService ()

Public methods

onBind

added in version 23.0.0
IBinder onBind (Intent intent)

Return the communication channel to the service. May return null if clients can not bind to the service. The returned IBinder is usually for a complex interface that has been described using aidl.

Note that unlike other application components, calls on to the IBinder interface returned here may not happen on the main thread of the process. More information about the main thread can be found in Processes and Threads.

Parameters
intent Intent: The Intent that was used to bind to this service, as given to Context.bindService. Note that any extras that were included with the Intent at that point will not be seen here.

Returns
IBinder Return an IBinder through which clients can call on to the service.

Protected methods

cleanUpSession

added in version 23.0.0
boolean cleanUpSession (CustomTabsSessionToken sessionToken)

Called when the client side IBinder for this CustomTabsSessionToken is dead. Can also be used to clean up IBinder.DeathRecipient instances allocated for the given token.

Parameters
sessionToken CustomTabsSessionToken: The session token for which the IBinder.DeathRecipient call has been received.

Returns
boolean Whether the clean up was successful. Multiple calls with two tokens holdings the same binder will return false.

extraCommand

added in version 23.0.0
Bundle extraCommand (String commandName, 
                Bundle args)

Unsupported commands that may be provided by the implementation.

Note:Clients should never rely on this method to have a defined behavior, as it is entirely implementation-defined and not supported.

This call can be used by implementations to add extra commands, for testing or experimental purposes.

Parameters
commandName String: Name of the extra command to execute.

args Bundle: Arguments for the command

Returns
Bundle The result Bundle, or null.

mayLaunchUrl

added in version 23.0.0
boolean mayLaunchUrl (CustomTabsSessionToken sessionToken, 
                Uri url, 
                Bundle extras, 
                List<Bundle> otherLikelyBundles)

Tells the browser of a likely future navigation to a URL.

The method warmup(long) has to be called beforehand. The most likely URL has to be specified explicitly. Optionally, a list of other likely URLs can be provided. They are treated as less likely than the first one, and have to be sorted in decreasing priority order. These additional URLs may be ignored. All previous calls to this method will be deprioritized.

Parameters
sessionToken CustomTabsSessionToken: The unique identifier for the session. Can not be null.

url Uri: Most likely URL.

extras Bundle: Reserved for future use.

otherLikelyBundles List: Other likely destinations, sorted in decreasing likelihood order. Each Bundle has to provide a url.

Returns
boolean Whether the call was successful.

newSession

added in version 23.0.0
boolean newSession (CustomTabsSessionToken sessionToken)

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
sessionToken CustomTabsSessionToken: Session token to be used as a unique identifier. This also has access to the CustomTabsCallback passed from the client side through getCallback().

Returns
boolean Whether a new session was successfully created.

postMessage

added in version 25.3.0
int postMessage (CustomTabsSessionToken sessionToken, 
                String message, 
                Bundle extras)

Sends a postMessage request using the origin communicated via requestPostMessageChannel(CustomTabsSessionToken, Uri). Fails when called before notifyMessageChannelReady(Bundle) is received on the client side.

Parameters
sessionToken CustomTabsSessionToken: The unique identifier for the session. Can not be null.

message String: The message that is being sent.

extras Bundle: Reserved for future use.

Returns
int An integer constant about the postMessage request result. Will return RESULT_SUCCESS if successful.

requestPostMessageChannel

added in version 25.3.0
boolean requestPostMessageChannel (CustomTabsSessionToken sessionToken, 
                Uri postMessageOrigin)

Sends a request to create a two way postMessage channel between the client and the browser linked with the given CustomTabsSession.

Parameters
sessionToken CustomTabsSessionToken: The unique identifier for the session. Can not be null.

postMessageOrigin Uri: A origin that the client is requesting to be identified as during the postMessage communication.

Returns
boolean Whether the implementation accepted the request. Note that returning true here doesn't mean an origin has already been assigned as the validation is asynchronous.

updateVisuals

added in version 23.1.0
boolean updateVisuals (CustomTabsSessionToken sessionToken, 
                Bundle bundle)

Updates the visuals of custom tabs for the given session. Will only succeed if the given session matches the currently active one.

Parameters
sessionToken CustomTabsSessionToken: The currently active session that the custom tab belongs to.

bundle Bundle: The action button configuration bundle. This bundle should be constructed with the same structure in CustomTabsIntent.Builder.

Returns
boolean Whether the operation was successful.

warmup

added in version 23.0.0
boolean warmup (long flags)

Warms up the browser process asynchronously.

Parameters
flags long: Reserved for future use.

Returns
boolean Whether warmup was/had been completed successfully. Multiple successful calls will return true.

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience.
(Sep 2017 survey)