skip to Main Content

I am using notifee to create notifications in a react native app. I noticed, by default notifications get blocked by android (See under Settings->Apps->My App). Do I have to set the permission somewhere in my app?

When I enable notifications in the Apps-Settings, they work fine, but I’d like them to be enabled when installing the apk.

2

Answers


  1. Yes, You have to explicitly request notifications permission if you targets Android 13.

    Paste the following line in AndroidManifest.xml:

    <uses-permission android:name="android.permission.POST_NOTIFICATION"/>
    

    And then in your app:

    import { PermissionsAndroid } from 'react-native' 
    
    const requestNotificationPermission = async () => {
    try {
      await PermissionsAndroid.request(
        PermissionsAndroid.PERMISSIONS.POST_NOTIFICATION
      )
    } catch (err) {
      if (_DEV_) console.warn('requestNotificationPermission error: ', err)
     }
    }
    

    Permission could be named "POST_NOTIFICATION" or "POST_NOTIFICATIONS", depending on your RN version.

    Login or Signup to reply.
  2. There is no need to request notification permission explicitly in android, even POST_NOTIFICATION is also deprecated,
    In android by default notification is enabled, until & unless you turnoff forcefully, for a simple solution,
    as you are using notifee, I will recommend using
    requestPermission function inside your parent/App.js component

    useEffect(() => {
        (async () => {
          // ask for notification permission
          await notifee.requestPermission();
        })();
    
        return () => {
          // this now gets called when the component unmounts
        };
      }, []);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search