Open ragsav opened 1 year ago
@ragsav I also had this issue and I fixed it with additional permission. You need to remove from manifest
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
and add
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
@roma-hladilka Still no notifications. Also I am not able to receive normal notifications.
I have the same problem only on Android. On iOS everything works fine.
3 months ago, it worked on Android, but now, it doesn't work. I don't know why.
I have the latest version 8.1.0
I tried to change android.permission.SYSTEM_ALERT_WINDOW
to android:name="android.permission.SCHEDULE_EXACT_ALARM"
but it doesn't work.
same issue i am also facing..
I was struggling simular situation.
and I found that PushNotification.configure
must be outside the component.
with IOS, it can be called if its in App.
but with Android, it's not called.
in example app, the configure is called in App. so it can recieve notification in any status with IOS. but not in inactive(=killed) with Android.
And also you can put breakpoint in index.js. even it stopped after you killed app, and recieve the notifcation.
same issue, can't push local noti on android. IOS working fine both remote and local.
is there anyone find solution for this issue?
Work at first times, but then not. I see that I received push, but it work and show only if app is closed(background). if reinstall package it work again. What's wrong?
For me, delete id on PushNotification.localNotificationSchedule then works well. https://github.com/zo0r/react-native-push-notification/issues/1707#issuecomment-923696626
If you are using id in the notification for android, it has to be a string of numbers and not letters or a mixture of letters and numbers. You could use just a number for the ID and it would work on the android but you wouldn't be able to use cancelLocalNotification because it requires a string of number. Also ensure that your configuration is in the index file outside of any component.
Thanks @Parkjunwu, your suggestion helped me narrow the problem down to being the ID in my case. I am now able to schedule notification.
I found local notifications were not showing on android after targeting sdk version >30. They changed PendingIntent in Android 12
This patch fixed it for me.
diff --git a/node_modules/react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java b/node_modules/react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java
index ad3527b..447a540 100644
--- a/node_modules/react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java
+++ b/node_modules/react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java
@@ -455,8 +455,13 @@ public class RNPushNotificationHelper {
int notificationID = Integer.parseInt(notificationIdString);
- PendingIntent pendingIntent = PendingIntent.getActivity(context, notificationID, intent,
- PendingIntent.FLAG_UPDATE_CURRENT);
+ PendingIntent pendingIntent = null;
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
+ pendingIntent = PendingIntent.getActivity(context, notificationID, intent, PendingIntent.FLAG_MUTABLE);
+ }
+ else {
+ pendingIntent = PendingIntent.getActivity(context, notificationID, intent, PendingIntent.FLAG_UPDATE_CURRENT);
+ }
NotificationManager notificationManager = notificationManager();
Hmmm... I'm having the same problem as @renanbronchart where iOS local notifications are fine but Android builds (SDK 31) are not showing notifications. I can alter and view scheduled notifications, they just don't fire. I did the following:
Still nothing. Can someone send some ideas my way?
@MorganTrudeau After adding patch for react-native-push-notification, moving .configure into index.js and changing id to numerical, localNotifcation() gets triggers but localNotificationSchedule() still doesn't get tigger. I also checked getScheduledLocalNotification(), notification is scheduled but no luck on triggering scheduled notification.
@infiniteline @revosambat Try with adding channelId and channelName like this channelId: 'default-channel', // (required) channelName: 'Default Channel', // (required)
i.e
PushNotification.localNotificationSchedule({ channelId: 'default-channel', // (required) channelName: 'Default Channel', // (required) title, message, date: fireDate, });
@ragsav If you are using Android 12 and above you may need to consider adding
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
to your AndroidManifest.xml
. And check if user has given permission to notificaitons.
You may want to ask user to give permission to use them.
same problem on Android 13
For Android 13, 14 using RN < 71.0, here is the fix:
I found local notifications were not showing on android after targeting sdk version >30. They changed PendingIntent in Android 12
This patch fixed it for me.
diff --git a/node_modules/react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java b/node_modules/react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java index ad3527b..447a540 100644 --- a/node_modules/react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java +++ b/node_modules/react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java @@ -455,8 +455,13 @@ public class RNPushNotificationHelper { int notificationID = Integer.parseInt(notificationIdString); - PendingIntent pendingIntent = PendingIntent.getActivity(context, notificationID, intent, - PendingIntent.FLAG_UPDATE_CURRENT); + PendingIntent pendingIntent = null; + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) { + pendingIntent = PendingIntent.getActivity(context, notificationID, intent, PendingIntent.FLAG_MUTABLE); + } + else { + pendingIntent = PendingIntent.getActivity(context, notificationID, intent, PendingIntent.FLAG_UPDATE_CURRENT); + } NotificationManager notificationManager = notificationManager();
This fixed my issue of local notifications not getting scheduled at a specific time, but you also have to add these permissions in AndroidManifest.xml file on devices with an Android version of at least 13:
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/> <uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>
However, it's important to note that using these permissions comes with a risk. App stores may reject your app because these permissions are potent, and there are policies in place for their careful use. An audit may lead to app removal if misuse is detected. Generally, such permissions are intended for clock or reminder apps. While you can hope that your app won't be rejected, it's advisable to consider an alternative approach: sending notifications remotely instead of scheduling them locally on your device. For more information, refer to this link
I have been trying the Scheduled local notifications but not a single notification is being triggered. I am not able to find exactly where I am doing mistake.
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.notes">
import PushNotification, {Importance} from 'react-native-push-notification'; import {CONSTANTS} from '../../constants';
export default class NotificationService { static configure() {} static createChannel() { PushNotification.channelExists( CONSTANTS.NOTIFICATION_CHANNEL_ID, exists => { if (exists) { console.log(
createChannel ${CONSTANTS.NOTIFICATION_CHANNEL_ID} already exists
, ); } else { PushNotification.createChannel( { channelId: CONSTANTS.NOTIFICATION_CHANNEL_ID, channelName: 'Notes channel', channelDescription: 'Notes notification channel', playSound: true, soundName: 'default', importance: Importance.HIGH, vibrate: true, }, created => console.log(createChannel returned '${created}'
), ); } }, ); } static getAllScheduledNotifications() { PushNotification.getScheduledLocalNotifications(notifications => { console.log(notifications); }); } static scheduleNotification({notificationID, title, description, timestamp}) { PushNotification.localNotificationSchedule({ date: new Date(timestamp), channelId: CONSTANTS.NOTIFICATION_CHANNEL_ID, id: notificationID, vibrate: true, vibration: 300, title: title, message: description, playSound: true, soundName: 'default', }); } static cancelNotification(notificationID) { PushNotification.cancelLocalNotification(notificationID); } }Is there any thing more which we need to change?