CustomTabsService


public abstract class CustomTabsService extends Service


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 types

@Retention(value = RetentionPolicy.SOURCE)
@IntDef(value = )
public annotation CustomTabsService.Relation
@Retention(value = RetentionPolicy.SOURCE)
@IntDef(value = )
public annotation CustomTabsService.Result

Constants

static final String
ACTION_CUSTOM_TABS_CONNECTION = "android.support.customtabs.action.CustomTabsService"

The Intent action that a CustomTabsService must respond to.

static final String
CATEGORY_COLOR_SCHEME_CUSTOMIZATION = "androidx.browser.customtabs.category.ColorSchemeCustomization"

An Intent filter category to signify that the Custom Tabs provider supports selecting and customizing color schemes via setColorScheme and setColorSchemeParams.

static final String
CATEGORY_NAVBAR_COLOR_CUSTOMIZATION = "androidx.browser.customtabs.category.NavBarColorCustomization"

An Intent filter category to signify that the Custom Tabs provider supports customizing the color of the navigation bar (setNavigationBarColor).

static final String
CATEGORY_TRUSTED_WEB_ACTIVITY_IMMERSIVE_MODE = "androidx.browser.trusted.category.ImmersiveMode"

An Intent filter category to signify that the Trusted Web Activity provider supports immersive mode.

static final String
CATEGORY_WEB_SHARE_TARGET_V2 = "androidx.browser.trusted.category.WebShareTargetV2"

An Intent filter category to signify that the Trusted Web Activity provider supports sending shared data according to the Web Share Target v2 protocol defined in https://wicg.github.io/web-share-target/level-2/.

static final int

A constant to be used with receiveFile indicating that the file is a splash image to be shown on top of a Trusted Web Activity while the web contents are loading.

static final String
KEY_SUCCESS = "androidx.browser.customtabs.SUCCESS"

The key to use to store a boolean in the returns bundle of extraCommand method, to indicate the command is executed successfully.

static final String
KEY_URL = "android.support.customtabs.otherurls.URL"

For mayLaunchUrl calls that wants to specify more than one url, this key can be used with putParcelable to insert a new url to each bundle inside list of bundles.

static final int

Used for validateRelationship.

static final int

Used for validateRelationship.

static final int

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

static final int

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

static final int

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

static final int

Indicates that the postMessage request was accepted.

static final String
TRUSTED_WEB_ACTIVITY_CATEGORY = "androidx.browser.trusted.category.TrustedWebActivities"

An Intent filter category to signify that the Custom Tabs provider supports Trusted Web Activities (see TrustedWebUtils for more details).

Public constructors

Public methods

@NonNull IBinder

Protected methods

boolean

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

abstract @Nullable Bundle
extraCommand(@NonNull String commandName, @Nullable Bundle args)

Unsupported commands that may be provided by the implementation.

boolean

Returns whether the Engagement Signals API is available.

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

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

abstract boolean

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

abstract int
@CustomTabsService.Result
postMessage(
    @NonNull CustomTabsSessionToken sessionToken,
    @NonNull String message,
    @Nullable Bundle extras
)

Sends a postMessage request using the origin communicated via requestPostMessageChannel.

abstract boolean
receiveFile(
    @NonNull CustomTabsSessionToken sessionToken,
    @NonNull Uri uri,
    int purpose,
    @Nullable Bundle extras
)

Receive a file from client by given Uri, e.g. in order to display a large bitmap in a Custom Tab.

abstract boolean
requestPostMessageChannel(
    @NonNull CustomTabsSessionToken sessionToken,
    @NonNull Uri postMessageOrigin
)

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

boolean
requestPostMessageChannel(
    @NonNull CustomTabsSessionToken sessionToken,
    @NonNull Uri postMessageOrigin,
    @Nullable Uri postMessageTargetOrigin,
    @NonNull Bundle extras
)

Same as above method with specifying the target origin to establish communication with.

boolean

Sets an EngagementSignalsCallback to execute callbacks for events related to the user's engagement with the webpage within the tab.

abstract boolean
updateVisuals(
    @NonNull CustomTabsSessionToken sessionToken,
    @Nullable Bundle bundle
)

Updates the visuals of custom tabs for the given session.

abstract boolean
validateRelationship(
    @NonNull CustomTabsSessionToken sessionToken,
    @CustomTabsService.Relation int relation,
    @NonNull Uri origin,
    @Nullable 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 Constants

From android.content.ComponentCallbacks2
static final int
static final int
static final int
static final int
static final int
static final int
static final int
From android.content.Context
static final String
ACCESSIBILITY_SERVICE = "accessibility"
static final String
ACCOUNT_SERVICE = "account"
static final String
ACTIVITY_SERVICE = "activity"
static final String
ALARM_SERVICE = "alarm"
static final String
APPWIDGET_SERVICE = "appwidget"
static final String
APP_OPS_SERVICE = "appops"
static final String
APP_SEARCH_SERVICE = "app_search"
static final String
AUDIO_SERVICE = "audio"
static final String
BATTERY_SERVICE = "batterymanager"
static final int
static final int
static final int
static final int
static final int
static final int
static final int
BIND_EXTERNAL_SERVICE = -2147483648
static final long
BIND_EXTERNAL_SERVICE_LONG = 4611686018427387904
static final int
static final int
static final int
static final int
static final int
static final int
static final String
BIOMETRIC_SERVICE = "biometric"
static final String
BLOB_STORE_SERVICE = "blob_store"
static final String
BLUETOOTH_SERVICE = "bluetooth"
static final String
BUGREPORT_SERVICE = "bugreport"
static final String
CAMERA_SERVICE = "camera"
static final String
CAPTIONING_SERVICE = "captioning"
static final String
CARRIER_CONFIG_SERVICE = "carrier_config"
static final String
CLIPBOARD_SERVICE = "clipboard"
static final String
COMPANION_DEVICE_SERVICE = "companiondevice"
static final String
CONNECTIVITY_DIAGNOSTICS_SERVICE = "connectivity_diagnostics"
static final String
CONNECTIVITY_SERVICE = "connectivity"
static final String
CONSUMER_IR_SERVICE = "consumer_ir"
static final int
static final int
static final int
static final String
CREDENTIAL_SERVICE = "credential"
static final String
CROSS_PROFILE_APPS_SERVICE = "crossprofileapps"
static final int
static final int
static final String
DEVICE_LOCK_SERVICE = "device_lock"
static final String
DEVICE_POLICY_SERVICE = "device_policy"
static final String
DISPLAY_HASH_SERVICE = "display_hash"
static final String
DISPLAY_SERVICE = "display"
static final String
DOMAIN_VERIFICATION_SERVICE = "domain_verification"
static final String
DOWNLOAD_SERVICE = "download"
static final String
DROPBOX_SERVICE = "dropbox"
static final String
EUICC_SERVICE = "euicc"
static final String
FILE_INTEGRITY_SERVICE = "file_integrity"
static final String
FINGERPRINT_SERVICE = "fingerprint"
static final String
GAME_SERVICE = "game"
static final String
GRAMMATICAL_INFLECTION_SERVICE = "grammatical_inflection"
static final String
HARDWARE_PROPERTIES_SERVICE = "hardware_properties"
static final String
HEALTHCONNECT_SERVICE = "healthconnect"
static final String
INPUT_METHOD_SERVICE = "input_method"
static final String
INPUT_SERVICE = "input"
static final String
IPSEC_SERVICE = "ipsec"
static final String
JOB_SCHEDULER_SERVICE = "jobscheduler"
static final String
KEYGUARD_SERVICE = "keyguard"
static final String
LAUNCHER_APPS_SERVICE = "launcherapps"
static final String
LAYOUT_INFLATER_SERVICE = "layout_inflater"
static final String
LOCALE_SERVICE = "locale"
static final String
LOCATION_SERVICE = "location"
static final String
MEDIA_COMMUNICATION_SERVICE = "media_communication"
static final String
MEDIA_METRICS_SERVICE = "media_metrics"
static final String
MEDIA_PROJECTION_SERVICE = "media_projection"
static final String
MEDIA_ROUTER_SERVICE = "media_router"
static final String
MEDIA_SESSION_SERVICE = "media_session"
static final String
MIDI_SERVICE = "midi"
static final int
MODE_APPEND = 32768
static final int
static final int

This field is deprecated.

static final int
static final int
static final int

This field is deprecated.

static final int

This field is deprecated.

static final String
static final String
NFC_SERVICE = "nfc"
static final String
NOTIFICATION_SERVICE = "notification"
static final String
NSD_SERVICE = "servicediscovery"
static final String
OVERLAY_SERVICE = "overlay"
static final String
PEOPLE_SERVICE = "people"
static final String
PERFORMANCE_HINT_SERVICE = "performance_hint"
static final String
POWER_SERVICE = "power"
static final String
PRINT_SERVICE = "print"
static final int
static final int
static final int
static final String
RESTRICTIONS_SERVICE = "restrictions"
static final String
ROLE_SERVICE = "role"
static final String
SEARCH_SERVICE = "search"
static final String
SENSOR_SERVICE = "sensor"
static final String
SHORTCUT_SERVICE = "shortcut"
static final String
STATUS_BAR_SERVICE = "statusbar"
static final String
STORAGE_SERVICE = "storage"
static final String
STORAGE_STATS_SERVICE = "storagestats"
static final String
SYSTEM_HEALTH_SERVICE = "systemhealth"
static final String
TELECOM_SERVICE = "telecom"
static final String
TELEPHONY_IMS_SERVICE = "telephony_ims"
static final String
static final String
TELEPHONY_SUBSCRIPTION_SERVICE = "telephony_subscription_service"
static final String
TEXT_CLASSIFICATION_SERVICE = "textclassification"
static final String
static final String
TV_INPUT_SERVICE = "tv_input"
static final String
TV_INTERACTIVE_APP_SERVICE = "tv_interactive_app"
static final String
UI_MODE_SERVICE = "uimode"
static final String
USAGE_STATS_SERVICE = "usagestats"
static final String
USB_SERVICE = "usb"
static final String
USER_SERVICE = "user"
static final String
VIBRATOR_MANAGER_SERVICE = "vibrator_manager"
static final String
VIBRATOR_SERVICE = "vibrator"

This field is deprecated.

static final String
VIRTUAL_DEVICE_SERVICE = "virtualdevice"
static final String
VPN_MANAGEMENT_SERVICE = "vpn_management"
static final String
WALLPAPER_SERVICE = "wallpaper"
static final String
WIFI_AWARE_SERVICE = "wifiaware"
static final String
WIFI_P2P_SERVICE = "wifip2p"
static final String
static final String
WIFI_SERVICE = "wifi"
static final String
WINDOW_SERVICE = "window"
From android.app.Service
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int

This field is deprecated.

static final int

Inherited methods

From android.content.Context
final int
getColor(int id)
final ColorStateList
final Drawable
getDrawable(int id)
final String
getString(int resId)
final T
<T> getSystemService(Class<T> serviceClass)
final CharSequence
getText(int resId)
final TypedArray
void
void
sendBroadcastWithMultiplePermissions(
    Intent intent,
    String[] receiverPermissions
)
From android.content.ContextWrapper
boolean
bindIsolatedService(
    Intent service,
    int flags,
    String instanceName,
    Executor executor,
    ServiceConnection conn
)
boolean
bindService(Intent service, ServiceConnection conn, int flags)
boolean
bindServiceAsUser(
    Intent service,
    ServiceConnection conn,
    int flags,
    UserHandle user
)
int
int
checkCallingOrSelfUriPermission(Uri uri, int modeFlags)
int[]
checkCallingOrSelfUriPermissions(List<Uri> uris, int modeFlags)
int
int
checkCallingUriPermission(Uri uri, int modeFlags)
int[]
checkCallingUriPermissions(List<Uri> uris, int modeFlags)
int
checkPermission(String permission, int pid, int uid)
int
int
checkUriPermission(Uri uri, int pid, int uid, int modeFlags)
int[]
checkUriPermissions(List<Uri> uris, int pid, int uid, int modeFlags)
void

This method is deprecated.

Context
Context
Context
Context
Context
createDeviceContext(int deviceId)
Context
Context
Context
createPackageContext(String packageName, int flags)
Context
createWindowContext(int type, Bundle options)
String[]
boolean
boolean
boolean
void
void
enforceCallingOrSelfUriPermission(
    Uri uri,
    int modeFlags,
    String message
)
void
enforceCallingPermission(String permission, String message)
void
enforceCallingUriPermission(Uri uri, int modeFlags, String message)
void
enforcePermission(String permission, int pid, int uid, String message)
void
enforceUriPermission(
    Uri uri,
    int pid,
    int uid,
    int modeFlags,
    String message
)
String[]
Context
ApplicationInfo
AssetManager
AttributionSource
String
Context
File
ClassLoader
File
ContentResolver
File
File
int
File
getDir(String name, int mode)
Display
File
File[]
File
File[]
File[]

This method is deprecated.

File
File
Executor
Looper
File
File
File[]
String
String
PackageManager
String
String
ContextParams
Resources
SharedPreferences
getSharedPreferences(String name, int mode)
Object
String
Resources.Theme
Drawable

This method is deprecated.

int

This method is deprecated.

int

This method is deprecated.

void
grantUriPermission(String toPackage, Uri uri, int modeFlags)
boolean
boolean
boolean
boolean
moveDatabaseFrom(Context sourceContext, String name)
boolean
moveSharedPreferencesFrom(Context sourceContext, String name)
FileInputStream
FileOutputStream
openFileOutput(String name, int mode)
SQLiteDatabase
openOrCreateDatabase(
    String name,
    int mode,
    SQLiteDatabase.CursorFactory factory
)
Drawable

This method is deprecated.

void
void
Intent
void

This method is deprecated.

void

This method is deprecated.

void
void
revokeUriPermission(Uri uri, int modeFlags)
void
void
void
sendOrderedBroadcast(Intent intent, String receiverPermission)
void
sendOrderedBroadcastAsUser(
    Intent intent,
    UserHandle user,
    String receiverPermission,
    BroadcastReceiver resultReceiver,
    Handler scheduler,
    int initialCode,
    String initialData,
    Bundle initialExtras
)
void

This method is deprecated.

void

This method is deprecated.

void
sendStickyOrderedBroadcast(
    Intent intent,
    BroadcastReceiver resultReceiver,
    Handler scheduler,
    int initialCode,
    String initialData,
    Bundle initialExtras
)

This method is deprecated.

void
sendStickyOrderedBroadcastAsUser(
    Intent intent,
    UserHandle user,
    BroadcastReceiver resultReceiver,
    Handler scheduler,
    int initialCode,
    String initialData,
    Bundle initialExtras
)

This method is deprecated.

void
setTheme(int resid)
void

This method is deprecated.

void
startActivities(Intent[] intents)
void
ComponentName
boolean
startInstrumentation(
    ComponentName className,
    String profileFile,
    Bundle arguments
)
void
startIntentSender(
    IntentSender intent,
    Intent fillInIntent,
    int flagsMask,
    int flagsValues,
    int extraFlags
)
ComponentName
boolean
void
void
void
void
void
updateServiceGroup(ServiceConnection conn, int group, int importance)
From android.app.Service
void
void
dump(FileDescriptor fd, PrintWriter writer, String[] args)
final Application
final int
void
void
void
void
void
onRebind(Intent intent)
void
onStart(Intent intent, int startId)

This method is deprecated.

int
onStartCommand(Intent intent, int flags, int startId)
void
onTaskRemoved(Intent rootIntent)
void
onTimeout(int startId)
void
onTrimMemory(int level)
boolean
onUnbind(Intent intent)
final void
startForeground(int id, Notification notification)
final void
stopForeground(boolean removeNotification)

This method is deprecated.

final void
final boolean
stopSelfResult(int startId)

Constants

ACTION_CUSTOM_TABS_CONNECTION

Added in 1.2.0
public static final String ACTION_CUSTOM_TABS_CONNECTION = "android.support.customtabs.action.CustomTabsService"

The Intent action that a CustomTabsService must respond to.

CATEGORY_COLOR_SCHEME_CUSTOMIZATION

Added in 1.2.0
public static final String CATEGORY_COLOR_SCHEME_CUSTOMIZATION = "androidx.browser.customtabs.category.ColorSchemeCustomization"

An Intent filter category to signify that the Custom Tabs provider supports selecting and customizing color schemes via setColorScheme and setColorSchemeParams.

CATEGORY_NAVBAR_COLOR_CUSTOMIZATION

Added in 1.2.0
public static final String CATEGORY_NAVBAR_COLOR_CUSTOMIZATION = "androidx.browser.customtabs.category.NavBarColorCustomization"

An Intent filter category to signify that the Custom Tabs provider supports customizing the color of the navigation bar (setNavigationBarColor).

CATEGORY_TRUSTED_WEB_ACTIVITY_IMMERSIVE_MODE

Added in 1.2.0
public static final String CATEGORY_TRUSTED_WEB_ACTIVITY_IMMERSIVE_MODE = "androidx.browser.trusted.category.ImmersiveMode"

An Intent filter category to signify that the Trusted Web Activity provider supports immersive mode.

CATEGORY_WEB_SHARE_TARGET_V2

Added in 1.2.0
public static final String CATEGORY_WEB_SHARE_TARGET_V2 = "androidx.browser.trusted.category.WebShareTargetV2"

An Intent filter category to signify that the Trusted Web Activity provider supports sending shared data according to the Web Share Target v2 protocol defined in https://wicg.github.io/web-share-target/level-2/.

FILE_PURPOSE_TRUSTED_WEB_ACTIVITY_SPLASH_IMAGE

Added in 1.2.0
public static final int FILE_PURPOSE_TRUSTED_WEB_ACTIVITY_SPLASH_IMAGE = 1

A constant to be used with receiveFile indicating that the file is a splash image to be shown on top of a Trusted Web Activity while the web contents are loading.

KEY_SUCCESS

Added in 1.3.0
public static final String KEY_SUCCESS = "androidx.browser.customtabs.SUCCESS"

The key to use to store a boolean in the returns bundle of extraCommand method, to indicate the command is executed successfully.

KEY_URL

Added in 1.2.0
public static final String KEY_URL = "android.support.customtabs.otherurls.URL"

For mayLaunchUrl calls that wants to specify more than one url, this key can be used with putParcelable to insert a new url to each bundle inside list of bundles.

RELATION_HANDLE_ALL_URLS

Added in 1.2.0
public static final int RELATION_HANDLE_ALL_URLS = 2

Used for validateRelationship. Requests the ability to handle all URLs from a given origin.

RELATION_USE_AS_ORIGIN

Added in 1.2.0
public static final int RELATION_USE_AS_ORIGIN = 1

Used for validateRelationship. 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.

RESULT_FAILURE_DISALLOWED

Added in 1.2.0
public static final int RESULT_FAILURE_DISALLOWED = -1

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

RESULT_FAILURE_MESSAGING_ERROR

Added in 1.2.0
public static final int RESULT_FAILURE_MESSAGING_ERROR = -3

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

RESULT_FAILURE_REMOTE_ERROR

Added in 1.2.0
public static final int RESULT_FAILURE_REMOTE_ERROR = -2

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

RESULT_SUCCESS

Added in 1.2.0
public static final int RESULT_SUCCESS = 0

Indicates that the postMessage request was accepted.

TRUSTED_WEB_ACTIVITY_CATEGORY

Added in 1.2.0
public static final String TRUSTED_WEB_ACTIVITY_CATEGORY = "androidx.browser.trusted.category.TrustedWebActivities"

An Intent filter category to signify that the Custom Tabs provider supports Trusted Web Activities (see TrustedWebUtils for more details).

Public constructors

CustomTabsService

Added in 1.2.0
public CustomTabsService()

Public methods

onBind

Added in 1.2.0
public @NonNull IBinder onBind(@Nullable Intent intent)

Protected methods

cleanUpSession

Added in 1.2.0
protected boolean cleanUpSession(@NonNull CustomTabsSessionToken sessionToken)

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

Parameters
@NonNull CustomTabsSessionToken sessionToken

The session token for which the 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 1.2.0
protected abstract @Nullable Bundle extraCommand(@NonNull String commandName, @Nullable 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. A return value of null will be used to signify that the client does not know how to handle the request. As optional best practices, KEY_SUCCESS could be use to identify that command was *successfully* handled. For example, when returning a message with result:

    Bundle result = new Bundle();
    result.putString("message", message);
    if (success)
        result.putBoolean(KEY_SUCCESS, true);
    return result;
The caller side:
    Bundle result = service.extraCommand(commandName, args);
    if (result.getBoolean(service.KEY_SUCCESS)) {
        // Command was successfully handled
    }
Parameters
@NonNull String commandName

Name of the extra command to execute.

@Nullable Bundle args

Arguments for the command

Returns
@Nullable Bundle

The result Bundle, or null.

isEngagementSignalsApiAvailable

Added in 1.6.0
protected boolean isEngagementSignalsApiAvailable(
    @NonNull CustomTabsSessionToken sessionToken,
    @NonNull Bundle extras
)

Returns whether the Engagement Signals API is available. The availability of the Engagement Signals API may change at runtime. If an EngagementSignalsCallback has been set, an onSessionEnded signal will be sent if the API becomes unavailable later.

Parameters
@NonNull CustomTabsSessionToken sessionToken

The unique identifier for the session.

@NonNull Bundle extras

Reserved for future use.

Returns
boolean

Whether the Engagement Signals API is available. A false value means setEngagementSignalsCallback will return false and not set the callback.

mayLaunchUrl

Added in 1.2.0
protected abstract boolean mayLaunchUrl(
    @NonNull CustomTabsSessionToken sessionToken,
    @Nullable Uri url,
    @Nullable Bundle extras,
    @Nullable List<Bundle> otherLikelyBundles
)

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

The method warmup 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
@NonNull CustomTabsSessionToken sessionToken

The unique identifier for the session. Can not be null.

@Nullable Uri url

Most likely URL.

@Nullable Bundle extras

Reserved for future use.

@Nullable List<Bundle> otherLikelyBundles

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 1.2.0
protected abstract boolean newSession(@NonNull 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
@NonNull CustomTabsSessionToken sessionToken

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 1.2.0
@CustomTabsService.Result
protected abstract int postMessage(
    @NonNull CustomTabsSessionToken sessionToken,
    @NonNull String message,
    @Nullable Bundle extras
)

Sends a postMessage request using the origin communicated via requestPostMessageChannel. Fails when called before notifyMessageChannelReady is received on the client side.

Parameters
@NonNull CustomTabsSessionToken sessionToken

The unique identifier for the session. Can not be null.

@NonNull String message

The message that is being sent.

@Nullable Bundle extras

Reserved for future use.

Returns
int

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

receiveFile

Added in 1.2.0
protected abstract boolean receiveFile(
    @NonNull CustomTabsSessionToken sessionToken,
    @NonNull Uri uri,
    int purpose,
    @Nullable Bundle extras
)

Receive a file from client by given Uri, e.g. in order to display a large bitmap in a Custom Tab. Prior to calling this method, the client grants a read permission to the target Custom Tabs provider via grantUriPermission. The file is read and processed (where applicable) synchronously.

Parameters
@NonNull CustomTabsSessionToken sessionToken

The unique identifier for the session.

@NonNull Uri uri

Uri of the file.

int purpose

Purpose of transferring this file, one of the constants enumerated in CustomTabsService#FilePurpose.

@Nullable Bundle extras

Reserved for future use.

Returns
boolean

true if the file was received successfully.

requestPostMessageChannel

Added in 1.2.0
protected abstract boolean requestPostMessageChannel(
    @NonNull CustomTabsSessionToken sessionToken,
    @NonNull Uri postMessageOrigin
)

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

Parameters
@NonNull CustomTabsSessionToken sessionToken

The unique identifier for the session. Can not be null.

@NonNull Uri postMessageOrigin

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.

requestPostMessageChannel

Added in 1.6.0
protected boolean requestPostMessageChannel(
    @NonNull CustomTabsSessionToken sessionToken,
    @NonNull Uri postMessageOrigin,
    @Nullable Uri postMessageTargetOrigin,
    @NonNull Bundle extras
)

Same as above method with specifying the target origin to establish communication with.

Parameters
@NonNull CustomTabsSessionToken sessionToken

The unique identifier for the session. Can not be null.

@NonNull Uri postMessageOrigin

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

@Nullable Uri postMessageTargetOrigin

The target Origin to establish PostMessageChannel with and send messages to.

@NonNull Bundle extras

Reserved for future use.

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.

setEngagementSignalsCallback

Added in 1.6.0
protected boolean setEngagementSignalsCallback(
    @NonNull CustomTabsSessionToken sessionToken,
    @NonNull EngagementSignalsCallback callback,
    @NonNull Bundle extras
)

Sets an EngagementSignalsCallback to execute callbacks for events related to the user's engagement with the webpage within the tab.

Parameters
@NonNull CustomTabsSessionToken sessionToken

The unique identifier for the session.

@NonNull EngagementSignalsCallback callback

The EngagementSignalsCallback to execute the callbacks.

@NonNull Bundle extras

Reserved for future use.

Returns
boolean

Whether the callback connection is allowed. If false, no callbacks will be called for this session.

updateVisuals

Added in 1.2.0
protected abstract boolean updateVisuals(
    @NonNull CustomTabsSessionToken sessionToken,
    @Nullable 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
@NonNull CustomTabsSessionToken sessionToken

The currently active session that the custom tab belongs to.

@Nullable 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 1.2.0
protected abstract boolean validateRelationship(
    @NonNull CustomTabsSessionToken sessionToken,
    @CustomTabsService.Relation int relation,
    @NonNull Uri origin,
    @Nullable 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. Otherwise the request didn't succeed. The client must call warmup before this.

Parameters
@NonNull CustomTabsSessionToken sessionToken

The unique identifier for the session. Can not be null.

@CustomTabsService.Relation int relation

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

@NonNull Uri origin

Origin for the relation query.

@Nullable Bundle extras

Reserved for future use.

Returns
boolean

true if the request has been submitted successfully.

warmup

Added in 1.2.0
protected abstract boolean warmup(long flags)

Warms up the browser process asynchronously.

Parameters
long flags

Reserved for future use.

Returns
boolean

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