Android 12 Developer Preview is here! Try it out, and give us your feedback!

CustomTabsCallback

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

A callback class for custom tabs client to get messages regarding events in their custom tabs. In the implementation, all callbacks are sent to the UI thread for the client.

Summary

Constants
static Int

Sent when loading was aborted by a user action before it finishes like clicking on a link or refreshing the page.

static Int

Sent when the tab couldn't finish loading due to a failure.

static Int

Sent when the tab has finished loading a page.

static Int

Sent when the tab has started loading a page.

static Int

Sent when the tab becomes hidden.

static Int

Sent when the tab becomes visible.

Public constructors

A callback class for custom tabs client to get messages regarding events in their custom tabs.

Public methods
open Unit
extraCallback(@NonNull callbackName: String, @Nullable args: Bundle?)

Unsupported callbacks that may be provided by the implementation.

open Bundle?
extraCallbackWithResult(@NonNull callbackName: String, @Nullable args: Bundle?)

The same as extraCallback, except that this method allows the custom tabs provider to return a result.

open Unit
onMessageChannelReady(@Nullable extras: Bundle?)

Called when CustomTabsSession has requested a postMessage channel through CustomTabsService#requestPostMessageChannel( * CustomTabsSessionToken, android.net.Uri) and the channel is ready for sending and receiving messages on both ends.

open Unit
onNavigationEvent(navigationEvent: Int, @Nullable extras: Bundle?)

To be called when a navigation event happens.

open Unit
onPostMessage(@NonNull message: String, @Nullable extras: Bundle?)

Called when a tab controlled by this CustomTabsSession has sent a postMessage.

open Unit
onRelationshipValidationResult(relation: Int, @NonNull requestedOrigin: Uri, result: Boolean, @Nullable extras: Bundle?)

Called when a relationship validation result is available.

Constants

static val NAVIGATION_ABORTED: Int

Sent when loading was aborted by a user action before it finishes like clicking on a link or refreshing the page.

Value: 4
static val NAVIGATION_FAILED: Int

Sent when the tab couldn't finish loading due to a failure.

Value: 3
static val NAVIGATION_FINISHED: Int

Sent when the tab has finished loading a page.

Value: 2
static val NAVIGATION_STARTED: Int

Sent when the tab has started loading a page.

Value: 1

TAB_HIDDEN

static val TAB_HIDDEN: Int

Sent when the tab becomes hidden.

Value: 6

TAB_SHOWN

static val TAB_SHOWN: Int

Sent when the tab becomes visible.

Value: 5

Public constructors

<init>

CustomTabsCallback()

A callback class for custom tabs client to get messages regarding events in their custom tabs. In the implementation, all callbacks are sent to the UI thread for the client.

Public methods

extraCallback

open fun extraCallback(
    @NonNull callbackName: String,
    @Nullable args: Bundle?
): Unit

Unsupported callbacks that may be provided by the implementation.

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

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

Parameters
callbackName String: Name of the extra callback.
args Bundle?: Arguments for the callback

extraCallbackWithResult

@Nullable open fun extraCallbackWithResult(
    @NonNull callbackName: String,
    @Nullable args: Bundle?
): Bundle?

The same as extraCallback, except that this method allows the custom tabs provider to return a result. A return value of null will be used to signify that the client does not know how to handle the callback. As optional best practices, CustomTabsService#KEY_SUCCESS could be use to identify that callback was *successfully* handled. For example, when returning a message with result:

<code>
          Bundle result = new Bundle();
          result.putString("message", message);
          if (success)
              result.putBoolean(CustomTabsService#KEY_SUCCESS, true);
          return result;
      </code>
The caller side:
<code>
          Bundle result = extraCallbackWithResult(callbackName, args);
          if (result.getBoolean(CustomTabsService#KEY_SUCCESS)) {
              // callback was successfully handled
          }
      </code>

onMessageChannelReady