Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Firebase Topic Messages with Android Notification Channels

I have an app with different notification types it can receive (for example News and Podcast). Currently it has two simple switches where the user can enable and disable those different notification types. It works by just subscribing and unsubscribing from the corresponding Firebase Topic for the type. The clear advantage is that the device only receives the notification the user wants and does not have to filter them locally => battery and data efficient.

Problem is, I want to combine it with the new android O notification channels. Am I right to assume that the only way is to just subscribe to all topics in Firebase and have the user manually disable unwanted ones in the android settings?

Is there a better way that saves more battery life (by not receiving all notifications)?

like image 986
Thomas Avatar asked Jul 31 '17 10:07

Thomas


1 Answers

The Notification Channel (a feature only needed for Android O -- presumably onwards) is (like) a parameter that you would (typically) use to sort/manage the notifications you build locally. --

Android O introduces notification channels to provide a unified system to help users manage notifications.

It doesn't necessarily disable receiving the notifications that you don't want to receive, but (AFAIK) notifications built without the Notification Channel won't show up/display in Android O (not received != not displayed). i.e. Your device may actually still be receiving the notifications, but just isn't displayed.

For Notifications sent through topics, so long as the corresponding registration token is subscribed, it is the expected behavior that the client would handle it accordingly.

With all that said, what you already have implemented (if I understand your post correctly -- subscribe and unsubscribe to topics based on a switch of some sort) is already the simplest as it could get.

If you want to totally disable notifications completely, you could call deleteInstanceId(). See my answers here and here for some additional info.

like image 183
AL. Avatar answered Nov 01 '22 01:11

AL.