added in version 24.1.0
belongs to Maven artifact com.android.support:customtabs:28.0.0-alpha1

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

 

@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 RELATION_HANDLE_ALL_URLS

Used for validateRelationship(int, Uri, Bundle).

int RELATION_USE_AS_ORIGIN

Used for validateRelationship(int, Uri, Bundle).

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)

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 validateRelationship(CustomTabsSessionToken sessionToken, int relation, Uri origin, Bundle extras)

Request to validate a relationship between the application and an origin.

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 24.1.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 24.1.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"

RELATION_HANDLE_ALL_URLS

added in version 27.1.0
int RELATION_HANDLE_ALL_URLS

Used for validateRelationship(int, Uri, Bundle). Requests the ability to handle all URLs from a given origin.

Constant Value: 2 (0x00000002)

RELATION_USE_AS_ORIGIN

added in version 27.1.0
int RELATION_USE_AS_ORIGIN

Used for validateRelationship(int, Uri, Bundle). For App -> Web transitions, requests the app to use the declared origin to be used as origin for the client app in the web APIs context.

Constant Value: 1 (0x00000001)

RESULT_FAILURE_DISALLOWED

added in version 25.4.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.4.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.4.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.4.0
int RESULT_SUCCESS

Indicates that the postMessage request was accepted.

Constant Value: 0 (0x00000000)

Public constructors

CustomTabsService

added in version 24.1.0
CustomTabsService ()

Public methods

onBind

added in version 24.1.0
IBinder onBind (Intent intent)

Parameters
intent Intent

Returns
IBinder

Protected methods

cleanUpSession

added in version 24.1.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 24.1.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 24.1.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 24.1.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.4.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.4.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 24.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.

validateRelationship

added in version 27.1.0
boolean validateRelationship (CustomTabsSessionToken sessionToken, 
                int relation, 
                Uri origin, 
                Bundle extras)

Request to validate a relationship between the application and an origin. If this method returns true, the validation result will be provided through onRelationshipValidationResult(int, Uri, boolean, Bundle). Otherwise the request didn't succeed. The client must call warmup(long) before this.

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

relation int: Relation to check, must be one of the CustomTabsService#RELATION_* constants.

origin Uri: Origin for the relation query.

extras Bundle: Reserved for future use.

Returns
boolean true if the request has been submitted successfully.

warmup

added in version 24.1.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.