Reputation: 41
I converted my PWA website to an Android App using Trusted Web Activity. But Push Notification is asking permissions to user.
How can we avoid this permission dialogue and make it working like a native app, sending notification without any permission.
If I list this pwa android app in play store this push notification permission will be asked or not.
Upvotes: 2
Views: 2685
Reputation: 149
It is possible to get notification permission without requesting it in the browser if you have a TWA app installed. It works through "Notification delegation" and the user implicitly agrees to receive push notifications by installing your app and not disabling app notifications.
You need to include something like this in your AndroidManifest:
<service android:name="com.google.androidbrowserhelper.trusted.DelegationService"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.support.customtabs.trusted.TRUSTED_WEB_ACTIVITY_SERVICE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</service>
Perhaps take a look at bubblewrap for more examples on how to get this to work.
Upvotes: 0
Reputation: 10870
As far as I know the TWA is a wrapper for your PWA, allowing you to store your PWA in the PlayStore.
A TWA can run in Android Chrome or in WebView inside an Android app. With the latter though, Web Notifications don't work, therefore I guess you go with the first approach.
In Chrome you still have to abide to the browser rules, meaning that you cannot skip to request permissions to the user.
Another thing to keep in mind is that PWAs and TWAs still run under the browser sandbox and this means they cannot access the native APIs.
Upvotes: 1