Android Question Target sdk 33 and firebase messaging confusion

tufanv

Expert
Licensed User
Longtime User
Hello,

With target sdk 33, we need to get permission for notifications as I understand. But also @Erel said that it is not needed for foreground service notification.
I am confused here. I am using new receivers for firebasemessaging module. I send notification with php using firebase cloud messaging. Do I need to implement to request permission?
@asales said:
Only if you will show a notification.
If you don't have permission, still receive the push notification, without show the notification in the statusbar.

So it means we need to implement this if we need to show it in status bar. What I need to achieve is, I need the notification to be shown to user when the app is on background because it will be a price alert notification to user when the app is on background.

So, my .notify code is in a receiver module called firebasemessaging. Should I implement the code in this receiver module ? If I implement the code in receiver module, It is not possible to ask for permission when the app is on background so I am totally lost here. Like in the ios, when user first opened the app, I need to request permission. After that, I should be able to send messages before earlier like target sdk 31.
 
Last edited:

tufanv

Expert
Licensed User
Longtime User
BTW if you don't check if hasPersmission (KVS) then no error should be displayed. If it does not has permission, no notification will be displayed. As i see your code, both circumstances do the same thing.
That is exacty What I am asking. If app has no permission, it wony show the notification as I understand. So why do we need to check permission before showing a notification?
 
Upvote 0

asales

Expert
Licensed User
Longtime User
So why do we need to check permission before showing a notification?
I don't check.

I ask for the permission to show notification when the user open the app for the first time.
If I don't has the permission, I can still receiver the firebase notification and I save it in a database and show a warning ("you have notification!") when the app is open.

In the FirebaseMessaging receiver, I check if the sqlite database is initializated to record the notification.
I don't check if I have permission to show or not the notification, I just try to show.

P.S(1): Tested in a Samsung A71 with Android 13.

P.S(2): I don't know if the Firebase message is still received in background if the Android put the app in hibernation.

P.S(3): I don't send more then 5 notifications per week to each app. I don't know how many notifications per day can be considered an abuse.
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
After some tests, I found out that if user doesn’t allow notifications, even if you send it or try to show it won’t display. So you don’t need to check for permission when sending or showing a notification.

It can just be useful if users wants to receive notifications but he didn’t allow lt, you can warn and ask him again
 
Upvote 0
Top