react-native-push-notification icon indicating copy to clipboard operation
react-native-push-notification copied to clipboard

[Android 13] Missing notifications permission

Open storm2513 opened this issue 2 years ago • 28 comments

Bug

Since Android API 33 developers are obliged to manually request permissions for push notifications

This library is not doing that for Android, so push notifications do not work on Android 13.

Would be nice to have that permissions request added when we use requestPermissions: true

storm2513 avatar Nov 23 '22 11:11 storm2513

@storm2513 I already add this but still not working in android 13

PushNotification.configure({ onRegister: function (token) { if (Platform.OS === 'android') { AsyncStorage.setItem('fcmToken', token.token); } }, permissions: { alert: true, badge: true, sound: true, }, popInitialNotification: true, requestPermissions: true, });

And i check the permission in setting of mobile of this app that was already granted

komailabbas12 avatar Nov 27 '22 19:11 komailabbas12

@storm2513 Please can you explain more on this please ??. having the same issues, not getting notifications on android. but works on iOS.

tdammy92 avatar Nov 30 '22 19:11 tdammy92

@tdammy92 add these two line in AndroidManifest.xml

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

komailabbas12 avatar Dec 05 '22 15:12 komailabbas12

@tdammy92 add these two line in AndroidManifest.xml

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

@komailabbas12 I did, even requsted Notification permission. did not work..

tdammy92 avatar Dec 05 '22 16:12 tdammy92

@tdammy92

Did you create a channel like this PushNotification.createChannel( { channelId: 'uzzapp', channelName: 'Uzzapp', channelDescription: 'Notification for special message', importance: 4, vibrate: true, }, (created) => console.log(createChannel returned '${created}') );

and then call the notification like this

PushNotification.localNotification({ channelId: 'uzzapp', channelName: 'Uzzapp', vibrate: true, allowWhileIdle: true, message: Your booking schedule on ${moment(paymentDetails?.selectedDate).format('MMMM Do YYYY')} at ${returnCheckinTime(paymentDetails)}, });

komailabbas12 avatar Dec 05 '22 16:12 komailabbas12

For me, first run of the app doesnt bring up permission request, it freezes (ANR) on real device but runs on emulator. For the second run it correctly shows the permission request and everything works fine. Google Play console is full of ANRs originating from this on android 13. Solved it by upgrading to android sdk level 33 to request permission with https://github.com/zoontek/react-native-permissions (although automatic launch for the app on emulator doesnt work with sdk 33 but it works on real device)

levepic avatar Dec 05 '22 16:12 levepic

Good afternoon everyone, today the same thing happened to me with my application and the solution for me was the following:

  1. Update the version of react-native-push-notification to the latest version (8.1.1).
  2. Add in your manifest the following two permissions:

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

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

  1. By default notification permissions in android 13 are disabled so your notification will not be displayed. To solve this problem you can execute the following two solutions:

3.1. The first and quickest solution to see if your app works is to enable notification permissions manually. To do this go to settings>notifications>app settings>all apps and activate notifications in your app.

3.2. The second solution is to use a package like react-native-permissions(3.6.1) and evaluate the notifications permission (request(PERMISSIONS.ANDROID.POST_NOTIFICATIONS)) so that it is displayed on the screen and the user can give the permissions . You could do something like the following

import { Platform } from 'react-native';
import { request, PERMISSIONS, RESULTS } from 'react-native-permissions';

class NotificationsPermissions {
    static async requestPermissionsNotifications() {
        if (Platform.OS === "android" && Platform.Version >= 33) {
            try {
                const result = await request(PERMISSIONS.ANDROID.POST_NOTIFICATIONS);
                // Handling the result of the permit request
                if (result === RESULTS.GRANTED) {
                    console.log('Permissions granted');
                } else {
                    console.log('Permissions not granted');
                }
            } catch (error) {
                // Error handling during permission request
                console.error(error);
            }
        }
    }
}

// use example 
NotificationsPermissions.requestPermissionsNotifications();


Note: Is important to take into account that every time a new version of Android comes out, focus your application on that latest version of your OS, in this case Android 14(34) or android 13(33).

Captura de pantalla 2024-03-16 a la(s) 12 17 28 p  m

I hope the answer can be of help to those who are having this problem. Greetings

cristian1206 avatar Feb 22 '23 22:02 cristian1206

Hi @cristian1206 , I think you forgot the two permissions you added at step 2. Can you give us some insights on this? Thanks!

gerardcastell avatar Mar 22 '23 11:03 gerardcastell

Good afternoon everyone, today the same thing happened to me with my application and the solution for me was the following:

  1. Update the version of react-native-push-notification to the latest version (8.1.1).

  2. Add in your manifest the following two permissions:

  3. By default notification permissions in android 13 are disabled so your notification will not be displayed. To solve this problem you can execute the following two solutions: 3.1. The first and quickest solution to see if your app works is to enable notification permissions manually. To do this go to settings>notifications>app settings>all apps and activate notifications in your app. 3.2. The second solution is to use a package like react-native-permissions(3.6.1) and evaluate the notifications permission (request(PERMISSIONS.ANDROID.POST_NOTIFICATIONS)) so that it is displayed on the screen and the user can give the permissions .

I hope the answer can be of help to those who are having this problem. Greetings

Worked! I also had to bump my targetSDKVersion to 33

17Amir17 avatar Apr 20 '23 19:04 17Amir17

Any update on this issue?

MehmoodArib avatar Apr 27 '23 05:04 MehmoodArib

permission was granted successfully but i don't get the notification. Help me

phhuong256 avatar Apr 28 '23 08:04 phhuong256

any update ? I still got error even after adding <uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" android:maxSdkVersion="32" /> <uses-permission android:name="android.permission.USE_EXACT_ALARM" android:maxSdkVersion="32" />

needs to hold android.permission.SCHEDULE_EXACT_ALARM or android.permission.USE_EXACT_ALARM to set exact alarms.

oddie13 avatar Apr 28 '23 10:04 oddie13

Hi @cristian1206 , I think you forgot the two permissions you added at step 2. Can you give us some insights on this? Thanks!

Hello everyone, how are you? I already updated my comment about the solution, apparently github did not take the code that I put. I hope it works for you.

cristian1206 avatar Apr 28 '23 13:04 cristian1206

Good afternoon everyone, today the same thing happened to me with my application and the solution for me was the following:

  1. Update the version of react-native-push-notification to the latest version (8.1.1).
  2. Add in your manifest the following two permissions:
  3. By default notification permissions in android 13 are disabled so your notification will not be displayed. To solve this problem you can execute the following two solutions: 3.1. The first and quickest solution to see if your app works is to enable notification permissions manually. To do this go to settings>notifications>app settings>all apps and activate notifications in your app. 3.2. The second solution is to use a package like react-native-permissions(3.6.1) and evaluate the notifications permission (request(PERMISSIONS.ANDROID.POST_NOTIFICATIONS)) so that it is displayed on the screen and the user can give the permissions .

I hope the answer can be of help to those who are having this problem. Greetings

Worked! I also had to bump my targetSDKVersion to 33

This is also important. In addition to this, it is important to take into account that every time a new version of Android comes out, focus your application on that latest version of your OS, in this case Android 13.

cristian1206 avatar Apr 28 '23 13:04 cristian1206

Good afternoon everyone, today the same thing happened to me with my application and the solution for me was the following:

  1. Update the version of react-native-push-notification to the latest version (8.1.1).
  2. Add in your manifest the following two permissions:

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

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

  1. By default notification permissions in android 13 are disabled so your notification will not be displayed. To solve this problem you can execute the following two solutions:

3.1. The first and quickest solution to see if your app works is to enable notification permissions manually. To do this go to settings>notifications>app settings>all apps and activate notifications in your app.

3.2. The second solution is to use a package like react-native-permissions(3.6.1) and evaluate the notifications permission (request(PERMISSIONS.ANDROID.POST_NOTIFICATIONS)) so that it is displayed on the screen and the user can give the permissions .

I hope the answer can be of help to those who are having this problem. Greetings

Used this to configure notification permission with Android 13 (SDK 33) - https://github.com/zoontek/react-native-permissions#requestnotifications

harry524483 avatar May 05 '23 09:05 harry524483

Bruh... I just had DND on... I debugged for 3 hours...

IceColdLight avatar Jul 26 '23 20:07 IceColdLight

Any soluion to this as I am stucked in notifications. Cannot get them on android. It comes in the console but the popup doesnot appear

umerdogar avatar Jul 31 '23 08:07 umerdogar

I was following the solution and still not working, but in my case I have to manually request notification permission to make notification showing up in the status bar and notification bar.

try { await PermissionsAndroid.request( PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS, ); } catch (error) { }

jumandika avatar Sep 13 '23 18:09 jumandika

Any soluion to this as I am stucked in notifications. Cannot get them on android. It comes in the console but the popup doesnot appear

same thing is happening with me also

yashnerkar avatar Jan 09 '24 08:01 yashnerkar

How can I ask notification permission for Android 13 and above in react native version 0.61 using POST_NOTIFICATIONS?

Faizansiddiqui287 avatar Mar 16 '24 09:03 Faizansiddiqui287

Hello @Faizansiddiqui287 , you can do something like the following:

import { Platform } from 'react-native';
import { request, PERMISSIONS, RESULTS } from 'react-native-permissions';

class NotificationsPermissions {
    static async requestPermissionsNotifications() {
        if (Platform.OS === "android" && Platform.Version >= 33) {
            try {
                const result = await request(PERMISSIONS.ANDROID.POST_NOTIFICATIONS);
                // Handling the result of the permit request
                if (result === RESULTS.GRANTED) {
                    console.log('Permissions granted');
                } else {
                    console.log('Permissions not granted');
                }
            } catch (error) {
                // Error handling during permission request
                console.error(error);
            }
        }
    }
}

// use example 
NotificationsPermissions.requestPermissionsNotifications();

cristian1206 avatar Mar 16 '24 14:03 cristian1206

Hello @Faizansiddiqui287 , you can do something like the following:

import { Platform } from 'react-native';
import { request, PERMISSIONS, RESULTS } from 'react-native-permissions';

class NotificationsPermissions {
    static async requestPermissionsNotifications() {
        if (Platform.OS === "android" && Platform.Version >= 33) {
            try {
                const result = await request(PERMISSIONS.ANDROID.POST_NOTIFICATIONS);
                // Handling the result of the permit request
                if (result === RESULTS.GRANTED) {
                    console.log('Permissions granted');
                } else {
                    console.log('Permissions not granted');
                }
            } catch (error) {
                // Error handling during permission request
                console.error(error);
            }
        }
    }
}

// use example 
NotificationsPermissions.requestPermissionsNotifications();

Hey thanks for your reply. This is my code. Below Android 13 it is working fine but for Android 13 and above it is giving permission is null error. Because I am using react native version 0.61 This is my code - if (Platform.OS === "android") {       try {         const OsVer = Platform.Version;         if (+OsVer >= 33) {           const res = await PermissionsAndroid.request(             PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS,           );           if (res === "granted") {             getTokenFCM();             onNotificationOpenedAppFromQuit();             listenToBackgroundNotifications();             listenToForegroundNotifications();             onNotificationOpenedAppFromBackground();           }         }         else {           getTokenFCM();           onNotificationOpenedAppFromQuit();           listenToBackgroundNotifications();           listenToForegroundNotifications();           onNotificationOpenedAppFromBackground();         }

Faizansiddiqui287 avatar Mar 16 '24 16:03 Faizansiddiqui287

Hello @Faizansiddiqui287 , you can do something like the following:

import { Platform } from 'react-native';
import { request, PERMISSIONS, RESULTS } from 'react-native-permissions';

class NotificationsPermissions {
    static async requestPermissionsNotifications() {
        if (Platform.OS === "android" && Platform.Version >= 33) {
            try {
                const result = await request(PERMISSIONS.ANDROID.POST_NOTIFICATIONS);
                // Handling the result of the permit request
                if (result === RESULTS.GRANTED) {
                    console.log('Permissions granted');
                } else {
                    console.log('Permissions not granted');
                }
            } catch (error) {
                // Error handling during permission request
                console.error(error);
            }
        }
    }
}

// use example 
NotificationsPermissions.requestPermissionsNotifications();

Hey thanks for your reply. This is my code. Below Android 13 it is working fine but for Android 13 and above it is giving permission is null error. Because I am using react native version 0.61 This is my code - if (Platform.OS === "android") {       try {         const OsVer = Platform.Version;         if (+OsVer >= 33) {           const res = await PermissionsAndroid.request(             PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS,           );           if (res === "granted") {             getTokenFCM();             onNotificationOpenedAppFromQuit();             listenToBackgroundNotifications();             listenToForegroundNotifications();             onNotificationOpenedAppFromBackground();           }         }         else {           getTokenFCM();           onNotificationOpenedAppFromQuit();           listenToBackgroundNotifications();           listenToForegroundNotifications();           onNotificationOpenedAppFromBackground();         }

If you have any solution for using POST_NOTIFICATION for react native version 0.61 please let me know

Faizansiddiqui287 avatar Mar 16 '24 16:03 Faizansiddiqui287

@Faizansiddiqui287 Try to follow these steps and if you can also review the note:

Good afternoon everyone, today the same thing happened to me with my application and the solution for me was the following:

  1. Update the version of react-native-push-notification to the latest version (8.1.1).
  2. Add in your manifest the following two permissions:

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

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

  1. By default notification permissions in android 13 are disabled so your notification will not be displayed. To solve this problem you can execute the following two solutions:

3.1. The first and quickest solution to see if your app works is to enable notification permissions manually. To do this go to settings>notifications>app settings>all apps and activate notifications in your app.

3.2. The second solution is to use a package like react-native-permissions(3.6.1) and evaluate the notifications permission (request(PERMISSIONS.ANDROID.POST_NOTIFICATIONS)) so that it is displayed on the screen and the user can give the permissions . You could do something like the following

import { Platform } from 'react-native';
import { request, PERMISSIONS, RESULTS } from 'react-native-permissions';

class NotificationsPermissions {
    static async requestPermissionsNotifications() {
        if (Platform.OS === "android" && Platform.Version >= 33) {
            try {
                const result = await request(PERMISSIONS.ANDROID.POST_NOTIFICATIONS);
                // Handling the result of the permit request
                if (result === RESULTS.GRANTED) {
                    console.log('Permissions granted');
                } else {
                    console.log('Permissions not granted');
                }
            } catch (error) {
                // Error handling during permission request
                console.error(error);
            }
        }
    }
}

// use example 
NotificationsPermissions.requestPermissionsNotifications();

Note: Is important to take into account that every time a new version of Android comes out, focus your application on that latest version of your OS, in this case Android 14(34) or android 13(33).

Captura de pantalla 2024-03-16 a la(s) 12 17 28 p  m

I hope the answer can be of help to those who are having this problem. Greetings

cristian1206 avatar Mar 16 '24 17:03 cristian1206

Hola@cristian1206Creo que olvidó los dos permisos que agregó en el paso 2. ¿Puede darnos alguna idea sobre esto? ¡Gracias!

Hello @gerardcastell , of course if these permissions are added within the AndroidManifest.xml, this file is located in the following path android/app/src/main/AndroidManifest.xml, as soon as you are in that path you add the following permissions:

cristian1206 avatar Mar 21 '24 15:03 cristian1206

@cristian1206 i getting this error after updating this code FYI : this issues happened while Importing this import { request, PERMISSIONS, RESULTS } from 'react-native-permissions';

ERROR Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'RNPermissions' could not be found. Verify that a module by this name is registered in the native binary. [Tue May 07 2024 16:18:06.651] ERROR Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication) [Tue May 07 2024 16:18:06.655] ERROR Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication)

chendhur007 avatar May 07 '24 10:05 chendhur007

Hi @chendhur007, this seems to be an error with the compilation. In this case it indicates that your RNPermissions module is not in the binary, to solve this error you must install your artifact again, that is, you must compile your app again at the native level.

For iOS: npx react-native run-ios

For android: npx react-native run-android

cristian1206 avatar May 07 '24 14:05 cristian1206

@Faizansiddiqui287 Try to follow these steps and if you can also review the note:

Good afternoon everyone, today the same thing happened to me with my application and the solution for me was the following:

  1. Update the version of react-native-push-notification to the latest version (8.1.1).
  2. Add in your manifest the following two permissions:

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

  1. By default notification permissions in android 13 are disabled so your notification will not be displayed. To solve this problem you can execute the following two solutions:

3.1. The first and quickest solution to see if your app works is to enable notification permissions manually. To do this go to settings>notifications>app settings>all apps and activate notifications in your app.

3.2. The second solution is to use a package like react-native-permissions(3.6.1) and evaluate the notifications permission (request(PERMISSIONS.ANDROID.POST_NOTIFICATIONS)) so that it is displayed on the screen and the user can give the permissions . You could do something like the following

import { Platform } from 'react-native';
import { request, PERMISSIONS, RESULTS } from 'react-native-permissions';

class NotificationsPermissions {
    static async requestPermissionsNotifications() {
        if (Platform.OS === "android" && Platform.Version >= 33) {
            try {
                const result = await request(PERMISSIONS.ANDROID.POST_NOTIFICATIONS);
                // Handling the result of the permit request
                if (result === RESULTS.GRANTED) {
                    console.log('Permissions granted');
                } else {
                    console.log('Permissions not granted');
                }
            } catch (error) {
                // Error handling during permission request
                console.error(error);
            }
        }
    }
}

// use example 
NotificationsPermissions.requestPermissionsNotifications();

Note: Is important to take into account that every time a new version of Android comes out, focus your application on that latest version of your OS, in this case Android 14(34) or android 13(33). Captura de pantalla 2024-03-16 a la(s) 12 17 28 p  m I hope the answer can be of help to those who are having this problem. Greetings

this saved my time

Thanks a lot

mcanikhilprajapati avatar Aug 22 '24 08:08 mcanikhilprajapati