Scheduling a notification causes a SecurityException on Android 12
See original GitHub issueI’m getting a SecurityException: Caller needs to hold android.permission.SCHEDULE_EXACT_ALARM to set exact alarms
on the following line:
https://github.com/zo0r/react-native-push-notification/blob/e1a07166d5e291a5c117fdbd4b5a45472616e771/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java#L178
Looks to be new behaviour with API level 31 as per the docs https://developer.android.com/training/scheduling/alarms#exact
The system invokes an exact alarm at a precise moment in the future. If your app targets Android 12 (API level 31) or higher, you must declare the “Alarms & reminders” special app access; otherwise, a SecurityException occurs.
May need to mention somewhere in the docs to add the <uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>
in the AndroidManifest.xml
.
As this permission can be disabled, the canScheduleExactAlarms()
(docs) check looks to be needed before trying to schedule an exact alarm.
I’m happy to make a PR with the proposed changes if needed
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top GitHub Comments
I used this patch to check
canScheduleExactAlarms()
:Hi,
https://github.com/zo0r/react-native-push-notification#state-of-the-repository
Regards