pushy/pushy-react-native

Notification in closed app state.

Closed this issue · 6 comments

I have my Manifest looking exactly like mentioned above. I'm also calling Pushy.setNotificationListener() within my App.js file before my component class. However, I still only receive the notification when the app is in the foreground and when it is in the background. When the app is swiped off the recent apps, the notification is not received.
"react-native": "0.61.5"
"pushy-react-native": "^1.0.14"


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

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <!-- Pushy Permissions -->                               
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <!-- End Pushy Permissions -->

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

      <!-- Pushy Declarations -->

      <!-- Pushy Notification Receiver -->
      <!-- Do not modify - internal BroadcastReceiver that forwards notifications to the internal notification service-->
      <receiver android:name="me.pushy.sdk.react.receivers.PushReceiver" android:exported="false">
          <intent-filter>
              <!-- Do not modify this -->
              <action android:name="pushy.me" />
          </intent-filter>
      </receiver>

      <!-- Pushy Update Receiver -->
      <!-- Do not modify - internal BroadcastReceiver that restarts the listener service -->
      <receiver android:name="me.pushy.sdk.receivers.PushyUpdateReceiver" android:exported="false">
          <intent-filter>
              <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
          </intent-filter>
      </receiver>

      <!-- Pushy Boot Receiver -->
      <!-- Do not modify - internal BroadcastReceiver that restarts the listener service -->
      <receiver android:name="me.pushy.sdk.receivers.PushyBootReceiver" android:exported="false">
          <intent-filter>
              <action android:name="android.intent.action.BOOT_COMPLETED"/>
          </intent-filter>
      </receiver>

      <!-- Pushy Socket Service -->
      <!-- Do not modify - internal service -->
      <service android:name="me.pushy.sdk.services.PushySocketService" android:stopWithTask="false" />

      <!-- Pushy Job Service (added in Pushy SDK 1.0.35) -->
      <!-- Do not modify - internal service -->
      <service android:name="me.pushy.sdk.services.PushyJobService"
          android:permission="android.permission.BIND_JOB_SERVICE"
          android:exported="true"
           />
          <!-- android:stopWithTask="false" -->

      <!-- End Pushy Declarations -->

      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:windowSoftInputMode="adjustPan"
        android:exported="true">
        <!-- <intent-filter>
        android:windowSoftInputMode="adjustResize"
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter> -->
      </activity>

      <activity
        android:name="com.zoontek.rnbootsplash.RNBootSplashActivity"
        android:theme="@style/BootTheme"> <!-- apply the theme you created at step 3. -->
        <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" />
    </application>

</manifest>


<!--placed before component class in App.js -->
Pushy.setNotificationListener(async (data) => {
  // Print notification payload data
  console.log("Received notification: " + JSON.stringify(data));

  // Notification title
  let notificationTitle = data.title;
  let notificationText = data.message || "Test notification";

  // Display basic system notification
  Pushy.notify(notificationTitle, notificationText, data);
});

Please help...

pushy commented

Hi @iampapagray,
Nice to connect with you. My name is John and I'd be glad to help you investigate this issue further.

If you could please provide the following information about the device experiencing this issue, that would be great:

  1. Device manufacturer
  2. Device model name
  3. Android OS version
pushy commented

Closing due to inactivity, please comment to reopen this issue, or reach out to us at https://support.pushy.me/hc/en-us.

Hi, i have same issue. Notification is not delivered while app is closed, but notification is showed once the app is opened. I have tested three device. Iphone is ok but vivo and samsun aren't.

Device manufacturer: Vivo
Device model name: Vivo 1901
Android OS version: android 11

Device manufacturer: Samsung
Device model name: Galaxy Tab A7 Lite
Android OS version: android 11

Device manufacturer: Apple
Device model name: Iphone X
Android OS version: IOS 15.3

pushy commented

Hi @chankahmun,
To ensure your users will be able to receive notifications in background / app closed / Doze mode on Chinese / Samsung devices, please consider integrating our FCM high-priority fallback delivery. Pushy will attempt to deliver your notifications through MQTT and Firebase Cloud Messaging's high priority channel simultaneously, effectively bursting through Doze mode and other third-party manufacturer power saving optimizations, and making it possible to receive notifications when your app is closed.

My users are mainly come from china. As I know, FCM are being blocked in china. Is it a solution if intergrating the app like what you suggested.

pushy commented

Hi @chankahmun,
Thanks for confirming.

Chinese device manufacturers and Samsung bundle their Android OS devices with custom power saving optimizations on top of the built-in Android OS ones, which are notorious for being even more aggressive at terminating background services than Android OS optimizations, to achieve longer battery life than the competition. Manufacturers notorious for these custom optimizations include:

  • Xiaomi
  • Huawei
  • OnePlus
  • Samsung
  • Oppo
  • Vivo
  • Asus
  • Sony
  • Honor

The problem with these custom power saving optimizations is that they're all named differently, located in different places in each device's Settings app, and cannot be overridden programmatically. The steps for whitelisting your app on each of these devices vary based on manufacturer and Android OS version. Dontkillmyapp.com does a pretty good job at explaining how to whitelist your app on each of these manufacturers. It is an unfortunate reality created by some of these Android device manufacturers that makes notification delivery unreliable on these specific phones without user intervention.

We suggest prompting the user with a friendly dialog asking them to whitelist your app from power optimizations in their device settings, in case they are using one of the devices notorious for killing background apps (check the value of android.os.Build.MANUFACTURER to determine if the device was manufactured by one of the above vendors).

Popular apps such as Facebook / WhatsApp / Instagram come pre-whitelisted on these devices, as device manufacturers want their users to have a great notification experience on these apps, but all other apps are automatically terminated in the background by these optimizations. That means notifications on those devices will only be delivered once those users reopen your app manually, or if they manually whitelist your app from each respective manufacturer's power saving optimizations.

We apologize for the inconvenience and lack of a workaround or solution. Please let me know if we may clarify anything further.