Android 10 & 11 local notifications doesn't show
See original GitHub issueOn emulators and physical devices with Android10+ the local notifications triggered with PushNotification.localNotification() don’t show on the top of the screen, just go to the system tray. I also checked on emulator with Android 8 and it works fine. Any ideas? 😃
package.json
“react-native”: “^0.63.4”, “react-native-push-notification”: “^7.2.2”,
AndroidManifest.xml
…
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <permission android:name="${applicationId}.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" /> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/> <uses-permission android:name="android.permission.WAKE_LOCK" />
…
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_name" android:value="YOUR NOTIFICATION CHANNEL NAME"/> <meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_description" android:value="YOUR NOTIFICATION CHANNEL DESCRIPTION"/> <meta-data android:name="com.dieam.reactnativepushnotification.notification_color" android:resource="@android:color/white"/> <!-- < Only if you're using GCM or localNotificationSchedule() > --> <receiver android:name="com.google.android.gms.gcm.GcmReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND" > <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <category android:name="${applicationId}" /> </intent-filter> </receiver> <!-- < Only if you're using GCM or localNotificationSchedule() > --> <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" /> <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver> <service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationRegistrationService"/> <!-- < Only if you're using GCM or localNotificationSchedule() > --> <service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerServiceGcm" android:exported="false" > <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> </intent-filter> </service> <!-- </ Only if you're using GCM or localNotificationSchedule() > --> <meta-data android:name="com.dieam.reactnativepushnotification.notification_foreground" android:value="true" /> <meta-data android:name="com.dieam.reactnativepushnotification.channel_create_default" android:value="true" /> <meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="push-notifications-channel" /> <receiver android:name="com.google.android.gms.gcm.GcmReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND" > <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <category android:name="............" /> </intent-filter> </receiver> <service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationRegistrationService" /> <service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerServiceGcm" android:exported="false" > <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> </intent-filter> </service> <service android:name=".java.MyFirebaseMessagingService" android:exported="false"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service>
settings.gradle
… include ‘:react-native-push-notification’ project(‘:react-native-push-notification’).projectDir = file(‘…/node_modules/react-native-push-notification/android’) include ‘:app’
Configuration
import PushNotification from ‘react-native-push-notification’; import {registerToPushNotifications} from ‘…’;
export const configureNotifications = () => { PushNotification.configure({ onNotification: notification => { console.log(‘onNotification:’, notification); }, onAction: notification => { console.log(‘onAction:’, notification); }, permissions: { alert: true, badge: true, sound: true, }, senderID: ‘bla-bla-bla’, popInitialNotification: true, requestPermissions: true, });
PushNotification.createChannel({ channelId: ‘push-notifications-channel’, channelName: ‘Push notifications channel’, channelDescription: ‘Push notifications channel’, playSound: true, soundName: ‘default’, importance: 4, vibrate: true, }); };
Trigger
const triggerNotification = () => { PushNotification.localNotification({ channelId: ‘push-notifications-channel’, channelName: ‘Push notifications channel’, foreground: true, ignoreInForeground: false, invokeApp: true, visibility: ‘private’, priority: ‘high’, vibrate: true, vibration: 500, playSound: true, soundName: ‘default’, autoCancel: true, title: ‘Title’, message: ‘Message’, bigText: ‘Big text’, subText: ‘Sub text’, }); };
Issue Analytics
- State:
- Created 3 years ago
- Comments:10
Top GitHub Comments
I am very confused on the channel usage too. Can someone provide more information on mocanSergiu666’s question?
Hi @mocanSergiu666 Please refer to the Channel Management, in the README. https://github.com/zo0r/react-native-push-notification#channel-management-android NOTE: Without channel, notifications don’t work Regards