DEV Community

Cover image for Asking Notification Permission in Android 13 for a React Native Application.

Asking Notification Permission in Android 13 for a React Native Application.

Gautham Vijayan on June 06, 2023

Introduction In this post we will look into how we can ask the user to allow notifications in the android part in our react native app when the us...
Collapse
 
rahulvyas profile image
Rahul Vyas

Do I really need to add the mentioned push notifications library? I'm using firebase messaging and notifee library for push notification. Can you update the article how to fix the target SDK 33 issue with these?

Collapse
 
narayanlava profile image
narayanthapa

Yes, you can utilize this for prompting notifications, and for other functionalities, you can incorporate FCM.

Collapse
 
dev3282 profile image
Lakshit Rattan

One issue with this now, when app is in background, upon clicking the notification, the app is supposed to open up from background to home page. But actually it does nothing at all, and the notification disappears. Happens only in android 13. Using @react-native-firebase/app and @react-native-firebase/messaging for notifications. Any leads with this ?

Collapse
 
gautham495 profile image
Gautham Vijayan

This also happens in Android 14. So I am using notifee with FCM combo to get it working for my apps.

Collapse
 
nahurodriguez profile image
Nahuel Rodriguez

Handy guide! it really helped me but only in the emulator, I don't understand why in the real device it never asks for permission, being exactly the same code. Any idea?

Collapse
 
gautham495 profile image
Gautham Vijayan

You have to check if the android version you are using is 13 and above. It wont ask if version is less than 12.

Collapse
 
nahurodriguez profile image
Nahuel Rodriguez

Thank you for explaining why it do not ask for permission. However, I am facing an issue where the notification appears in the emulator but not on a real device.

Thread Thread
 
gautham495 profile image
Gautham Vijayan

Yeah please check if the android version is 13 or above in your real device and let me know.

Thread Thread
 
nahurodriguez profile image
Nahuel Rodriguez

I was able to solve it based on what you told me, by not asking for permission the validation that arrived was a different one, instead of 'granted' it was 'never ask again'. My emulator was a different android version than my mobile.

Thread Thread
 
gautham495 profile image
Gautham Vijayan

Glad to know it worked!

Collapse
 
atultiwaree profile image
Atul Tiwaree

thanks man there were 0 tutorial regarding this

Collapse
 
gautham495 profile image
Gautham Vijayan

Glad it helped you out.

Collapse
 
madmax profile image
yash nerkar

How to use this component and where should I import

Collapse
 
andrewzey profile image
Andrew Zey

Thank you, this saved us a ton of headache!

Collapse
 
sourav_dey_7a89559d565f05 profile image
sourav dey

Thanks dude

Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
johhansantana profile image
Johhan Santana • Edited

life saver dude! Right now updating react native from 0.65 to .70+ has been such a pain just for updating the android sdk api version. One thing I wanted to add is if you don't want to always make the changes when doing npm install or yarn install is to use patch-package library to make a patch of the changes which will save those edits even if you clean your node_modules folder and reinstall

yarn patch-package react-native
Enter fullscreen mode Exit fullscreen mode

I wanted to ask if there was a way to check if the app has permissions for notifications without asking the user? We had a logic that checked the permission using react native firebase library with messaging().hasPermission() but this now does not work.

Thanks!