0

Can I ask users' permission to receive Firebase push notifications and to allow users to opt out from receiving push notifications when first run the app?

I know that push notification permissions are included in the normal and not dangerous category permissions and we don't have to ask for push notification permission but is there any workaround?

Grinton
  • 3
  • 2

1 Answers1

1

Basically what you would want to do in this case is use the Firebase Subscriptions.

Firebase Subscriptions allows you to subscribe or unsubscribe to a particular topic and that allows for a behaviour like only the users which are subscribed to a particular topic will receive the push notifications

You can subscribe or unsubscribe a user from the topic or in simple words stop or enable notifications based on a toggle in the settings say for example

To see a sample as to how to subscribe to a topic you can do something like

FirebaseMessaging.getInstanceId().subscribeToTopic("topic")

More details here

And then to unsubscribe you can check this example

For more info about subscriptions you can refer to official Firebase Docs

gtxtreme
  • 1,830
  • 1
  • 13
  • 25
  • Thanks, this is exactly what I need! – Grinton Sep 16 '21 at 16:58
  • And do you know if it would be possible to untoggle the push notification settings once the user unsubscribed from a topic? – Grinton Sep 16 '21 at 17:02
  • You don't need to actually know when a user unsubscribes from a notification. You just need to make a preferences screen and add all the preferences to the SharedPreferences. Then check from there whether to enable the subscription or not. When toggling write to the SharedPreferences directly. Fallback case will be subscribe by default. You can also have the user preferences on a different server to be sure that even if SharedPreferences is cleared you accurately have the choice of the user, resulting in better user experience – gtxtreme Sep 16 '21 at 17:07
  • Thanks again, very useful explanation! – Grinton Sep 16 '21 at 20:46