react-native-push-notification: Local Notifications not working in android

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">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

<application
  android:name=".MainApplication"
  android:label="@string/app_name"
  android:icon="@drawable/ic_launcher"
  android:roundIcon="@drawable/ic_launcher_round"
  android:allowBackup="false"
  android:theme="@style/BootTheme">

  <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationActions" android:exported="false"/>
  <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" android:exported="false"/>
  <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver" android:exported="false">
      <intent-filter>
          <action android:name="android.intent.action.BOOT_COMPLETED" />
          <action android:name="android.intent.action.QUICKBOOT_POWERON" />
          <action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
      </intent-filter>
  </receiver>

  <service
      android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
      android:exported="false" >
      <intent-filter>
          <action android:name="com.google.firebase.MESSAGING_EVENT" />
      </intent-filter>
  </service>

  <meta-data  android:name="com.dieam.reactnativepushnotification.notification_foreground"
              android:value="false"/>
  <meta-data  android:name="com.dieam.reactnativepushnotification.notification_color"
              android:resource="@android:color/white"/>

  
  
  <activity
    android:name=".MainActivity"
    android:label="@string/app_name"
    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
    android:launchMode="singleTask"
    android:windowSoftInputMode="adjustResize"
    android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
  </activity>
  
  
</application>
</manifest>

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?

About this issue

Commits related to this issue

Most upvoted comments

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:

  • moved .configure into index.js
  • tried the permission change suggested by @roma-hladilka
  • verified that IDs are numerical
  • changed the code in RNPushNotificationHelper.java that was pushed by @thanhtuttm

Still nothing. Can someone send some ideas my way?

@roma-hladilka Still no notifications. Also I am not able to receive normal notifications.

@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" />