PWA cannot enable app notifications in an Android TWA (Trusted Web Activity)?

1 week ago 18
ARTICLE AD BOX

Notification.requestPermission() in the PWA is not triggering the Android app / TWA to change Notificaitions to "granted" instead of "blocked".

Using the most recent version of Google Bubblewrap, I created a Trusted Web Activity (TWA) Android wrapper for my PWA (Progressive Web App) created using SolidJS. My Android code uses:

public class DelegationService extends com.google.androidbrowserhelper.trusted.DelegationService

so that when the PWA requests Notification.requestPermission(), the TWA should pass the request up to the TWA android wrapper and enable the app's Notifications instead of just the browser's notifications.

However, when the PWA calls Notification.requestPermission() and the user selects "Allow", the PWA returns "granted", but the application's notifications permission is still "blocked".

I've verified that I'm following all of the instructions for gradle, etc. and I've tried a 100 variations, but it's still happening. This seems like this should be straightforward and common: enable a PWA to enable notifications in the TWA android wrapper, and yet I'm stumped.

Ideas?

implementation 'com.google.androidbrowserhelper:androidbrowserhelper:2.6.2'

The steps I using to run it is:

adb uninstall com.testapp.www.twa fastlane android install_debug adb logcat -T "$(date +'%m-%d %H:%M:%S.%q' -d '1 seconds ago')" -s "FirebaseMsgService" "LauncherActivity" "cr_TrustedWebActivity" "chromium" "ActivityTaskManager" "LogErrorOperation" "FirebaseMessaging" "FirebaseMessagingService" "NotificationManager" "MyApplication" "TwaApplication" "TwaDelegationService" "OriginVerifier" "Notifications"

When I connect to the android device with Chrome Dev tools, and click on the PWA button to enable notifications, I'm getting confirmation in the Chrome console that the Notification.requestPermission() is succeeding and I'm able to click on "Allow" in the system pop-up, with these console log entries:

Requesting notification permission via Web API. DIAGNOSTIC: Web API notification permission result: granted

However, it appears that the Notification.requestPermission() isn't being intercepted by the TWA/Android/"DelegationService extends com.google.androidbrowserhelper.trusted.DelegationService" code, and so there is no logs being sent to adb logcat during the actual clicking and Notification.requestPermission step. I'm running this on the device, so I'm not sure how to get log output into the `com.google.androidbrowserhelper.trusted.DelegationService code.

This is the class I'm extending: https://github.com/GoogleChrome/android-browser-helper/blob/main/androidbrowserhelper/src/main/java/com/google/androidbrowserhelper/trusted/DelegationService.java

This is the code that appears do be doing the heavy liftin in the Android code to actually get and change the Android app's Notification permission, but I'm not sure how this connects into my code, and it isn't referenced in the documentation: https://github.com/GoogleChrome/android-browser-helper/blob/main/androidbrowserhelper/src/main/java/com/google/androidbrowserhelper/trusted/NotificationPermissionRequestActivity.java

Read Entire Article