public abstract class TrustedWebActivityService
extends Service

   ↳ android.content.Context
     ↳ android.content.ContextWrapper
         ↳ androidx.browser.trusted.TrustedWebActivityService

The TrustedWebActivityService lives in a client app and serves requests from a Trusted Web Activity provider. At present it only serves requests to do with notifications.

When the provider receives a notification from a scope that is associated with a Trusted Web Activity client app, it will attempt to connect to a TrustedWebActivityService and forward calls. This allows the client app to display the notifications itself, meaning it is attributable to the client app and is managed by notification permissions of the client app, not the provider.

TrustedWebActivityService is usable as it is, by adding the following to your AndroidManifest:


     <meta-data android:name=""
         android:resource="@drawable/ic_notification_icon" />

         <action android:name=""/>
         <category android:name="android.intent.category.DEFAULT"/>
The SMALL_ICON resource should point to a drawable to be used for the notification's small icon.

Alternatively for greater customization, TrustedWebActivityService can be extended and overridden. In this case the manifest entry should be updated to point to the extending class.

As this is an AIDL Service, calls may come in from different Binder threads, so overriding implementations need to be thread safe [1].

For security, the TrustedWebActivityService will check that whatever connects to it matches the Token stored in the TokenStore returned by getTokenStore(). This is because we don't want to allow any app on the users device to connect to this Service be able to make it display notifications. [1]:




An Intent Action used by the provider to find the TrustedWebActivityService or subclass.


The key to use to store a Bitmap to return from the onGetSmallIconBitmap() method.


The key to use to store a boolean in the returns bundle of onExtraCommand(String, Bundle, TrustedWebActivityCallbackRemote) method, to indicate whether the command is executed successfully.


The Android Manifest meta-data name to specify a small icon id to use.


Used as a return value of onGetSmallIconId() when the icon is not provided.

Inherited constants

Public constructors


Public methods

abstract TokenStore getTokenStore()

Returns a TokenStore that is used to determine whether the connecting package is allowed to connect to this service.

boolean onAreNotificationsEnabled(String channelName)

Checks whether notifications are enabled.

final IBinder onBind(Intent intent)
void onCancelNotification(String platformTag, int platformId)

Cancels a notification.

void onCreate()

Called by the system when the service is first created.

Bundle onExtraCommand(String commandName, Bundle args, TrustedWebActivityCallbackRemote callbackRemote)

Contains a free form command from the browser.

Bundle onGetSmallIconBitmap()

Returns a Bundle containing a bitmap to be use as the small icon for any notifications.

int onGetSmallIconId()

Returns the Android resource id of a drawable to be used for the small icon of the notification.

boolean onNotifyNotificationWithChannel(String platformTag, int platformId, Notification notification, String channelName)

Displays a notification.

final boolean onUnbind(Intent intent)

Inherited methods