I'm using Firebase console to send notifications to users. However I want to let users disable notifications. How can I disable them?
I am able to handle (and stop) notifications through FirebaseMessagingService only when the app is in foreground. But I cannot stop notifications when the app is in background.
You can handle all push events from all difference services (with Firebase). First create
YouUniversalFCM extends WakefulBroadcastReceiver
For example:
Next in
AndroidManifest.xml
Replace
YOUR_PACKAGE
by the package of your app. That's all. If you want to subscribe for another push service, you must be addYourTokenService
And declared in
AndroidManifest.xml
I meet the same question. I use subscribeToTopic API to subscribe the notification.
And I find the other API unsubscribeFromTopic to unsubscribe.
Maybe it would be useful for APP using topic notification. It would not receive notification in foreground and background.
I couldn't comment yet, but racs' comment helped me a lot.
So basically, I changed the body for the push notification request from:
To:
Now my app calls onMessageReceived() everytime even in background, and I just changed the methods to use the obtained notification title and message in the push data.
Not sure why this happens to you (code snippet maybe?), but there is a heavy weight ultimate solution: define your own c2dm receiver in the manifest and set the priority high (>0) then stop the notification from processing.
GCM messages are processed as ordered broadcasts, so you can stop the processing chain by calling this method:
https://developer.android.com/reference/android/content/BroadcastReceiver.html#abortBroadcast()
If you don't do anything in your receiver then the next receiver will do the processing, which will be the Firebase receiver.
Please note: Firebase is sending push notification for Remote Config changes. So, if you use Remote Config then it is not advisable to suppress any data push.
I had this problem.and solved by use below code:
Enable Firebase Notifications:
Disable Firebase Notifications: deleteInstanceId() is a blocking call. It cannot be called on the main thread.