question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android did not receive any notification, but IOS working properly

See original GitHub issue

Question

this is wierd actually, a day ago on Android , the push notification is working even when application is on Foreground or Background. then im going for implement it on IOS, its working too even in Debug or Release.

but, when i try to test on Android again, look like it got some problem. it’s working if im test using Firebase Console by targeting Device Token Directly, but when i try to Target to App like bellow, its now not working, same as if im close the application.

Working : image

Not Working : image

i have test it send to both Ios and Android, the the result is IOS got the push notification, but Android is NOT.

Here’s the code i have using on my React Native code :

async componentDidMount(){
      this.pushNotificationListener();
    }

    pushNotificationListener = async () => {
           //Handling like this because on IOS, onNotification not Fired, and i ended doing something dirty like so, sad but working
       messaging().onMessage((payload) => {
         console.log('[payload] : ',payload)
         this.showNotification(payload)
      });
      PushNotification.configure({
        // (optional) Called when Token is generated (iOS and Android)
        onRegister:  (token) => {
          console.log("TOKEN:", token);
        },
        // (required) Called when a remote or local notification is opened or received
        onNotification:  (notification) => {
          console.log("NOTIFICATION:", notification);
          // process the notification
          this.showNotification(notification)
          // required on iOS only (see fetchCompletionHandler docs: https://github.com/react-native-community/react-native-push-notification-ios)
          notification.finish(PushNotificationIOS.FetchResult.NoData);
        },
        // ANDROID ONLY: FCM Sender ID (product_number) (optional - not required for local notifications, but is need to receive remote push notifications)
        senderID: "Some Sender ID",
        // IOS ONLY (optional): default: all - Permissions to register.
        permissions: {
          alert: true,
          badge: true,
          sound: true,
        }
      });
    }

    showNotification = (payload) => {
     //Handling like this because on IOS, onNotification not Fired, and i ended doing something dirty like so, sad but working
      let notification = {
        title : Platform.OS === 'ios' ? payload.notification.title : payload.title,
        message : Platform.OS === 'ios' ? payload.notification.body : payload.message
      };

      PushNotification.localNotification({
        largeIcon: "ic_launcher", // (optional) default: "ic_launcher"
        smallIcon: "ic_launcher", // (optional) default: "ic_notification" with fallback for "ic_launcher"
        bigText: notification.message, // (optional) default: "message" prop
        vibrate: true,
        priority: "max",
        allowWhileIdle: true,

        title: notification.title, // (optional)
        message: notification.message, // (required)
      });
    }

Package.json :

    "react-native-push-notification": "^3.1.9",
    "@react-native-community/push-notification-ios": "^1.1.1",
    "@react-native-firebase/app": "6.4.1.alpha0",
    "@react-native-firebase/messaging": "6.4.1.alpha0",

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.testapp">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <permission
        android:name="com.testapp.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    <uses-permission android:name="com.testapp.permission.C2D_MESSAGE" />
    <!-- < Only if you're using GCM or localNotificationSchedule() > -->

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

    <application
      android:usesCleartextTraffic="true"
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:allowBackup="false"
      android:theme="@style/AppTheme">
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:windowSoftInputMode="adjustResize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
      </activity>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
      <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"/>
        <!-- Change the resource name to your App's accent color - or any other color you want -->
        <meta-data  android:name="com.dieam.reactnativepushnotification.notification_color"
                    android:resource="@color/white"/> <!-- or @android:color/{name} to use a standard color -->

        <!-- < 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="com.testapp" />
            </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() > -->

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

</manifest>


Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:23

github_iconTop GitHub Comments

1reaction
Dallas62commented, Apr 23, 2020

@bobbyrinaldy I will investigate ASAP

0reactions
github-actions[bot]commented, Jun 26, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android Notifications Not Showing Up? 10 Fixes You Can Try
Not seeing notifications show up on your Android phone? Try these fixes to get Android notifications working again.
Read more >
How to Fix Notifications Not Showing up on Android - Lifewire
If you aren't receiving notifications from a specific app, the most likely culprit is the notification settings for that app. Every app has...
Read more >
Top 8 Ways to Fix Notifications Not Working on iPhone
Top 8 Ways to Fix Notifications Not Working on iPhone · 1. Restart iPhone · 2. Disable Focus Mode · 3. Disable Scheduled...
Read more >
Notifications Not Shown - Mobile Push
Android App is Force Stopped ; MIUI 10, Settings > Battery & performance > Choose apps > Select the app that is not...
Read more >
iPhone Notifications Not Working? Here's The Real Fix!
Go to Settings -> Notifications and tap on the app that you're not receiving notifications from. Make sure the switch next to Allow ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found