robin.h
robin.h

Reputation: 91

How do I return the user to my TWA when pressing on a media notification?

I'm building an Android app that wraps my Progressive Web App as a Trusted Web Activity. (I'm following guidelines from Google's sample project.)

When the user plays audio in the app, a media notification appears on the device. I'm using the web Media Session API to customise the content of this notification.

If running the PWA in a normal web browser, once the notification appears, pressing it returns the user to the relevant browser tab. (If the phone is locked, the user is prompted to unlock.)

If the media notification is triggered from the TWA, pressing on it does nothing. (Other functionality such as play/pause works as expected.)

The Media Session API is fairly limited in scope. MediaSession action types do not include an action to focus the app.

navigator.mediaSession.setActionHandler('pause', () => {
            audioElement.pause();
            navigator.mediaSession.playbackState = 'paused';
        });

        navigator.mediaSession.setActionHandler('play', () => {
            audioElement.play();
            navigator.mediaSession.playbackState = 'playing';
        });

navigator.mediaSession.metadata = new MediaMetadata({
            title: 'App',
            artist: 'Name',
            artwork: [
                { src: '/android-chrome-192x192.png?v=47rE43RRzB', sizes: '192x192', type: 'image/png' },
                { src: '/android-chrome-512x512.png?v=47rE43RRzB', sizes: '512x512', type: 'image/png' },
            ],
        });

When the media notification is trigged from the TWA, I expect the same functionality as when it is triggered from a web browser such as Chrome.

That includes the returning the user to the TWA (or prompting the user to unlock the device) when the notification is pressed anywhere except the play/pause control.

Everything else works except this aspect.

Upvotes: 4

Views: 224

Answers (1)

Kartik Jain
Kartik Jain

Reputation: 74

This was the default action in pwa and web, whenever someone clicks on notification media control, its takes to the website or pwa, but in twa its broken, its taking to the chrome browser but not focusing the app or website. I already raised ticket for the same on github

Upvotes: 0

Related Questions