zo0r / react-native-push-notification

React Native Local and Remote Notifications
MIT License
6.75k stars 2.05k forks source link

Notifications appear ONLY after opening the app! #1574

Open wmonecke opened 4 years ago

wmonecke commented 4 years ago

Bug

Hi there!

Amazing work with this package and it is working almost flawlessly. However, some of my android users have reported that their scheduled notifications are not arriving and are only being shown AFTER they have opened the app. This can be many notifications being shown at once if more than one scheduled notification already passed.

I did not see any other similar issue being open and wanted to see if anyone else has experienced this issue? All notifications within the app are scheduled locally.

On iOS it hasn't been reported!

Environment info

react-native info output:

System:
    OS: macOS 10.15.3
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
    Memory: 65.34 MB / 16.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 8.9.4 - /usr/local/bin/node
    npm: 6.9.0 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 13.5, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
    Android SDK:
      API Levels: 23, 25, 26, 27, 28
      Build Tools: 26.0.2, 26.0.3, 27.0.2, 27.0.3, 28.0.2, 28.0.3
      System Images: android-28 | Google Play Intel x86 Atom, android-P | Google APIs Intel x86 Atom
  IDEs:
    Android Studio: 3.4 AI-183.6156.11.34.5692245
    Xcode: 11.5/11E608c - /usr/bin/xcodebuild
  npmPackages:
    react: 16.8.6 => 16.8.6 
    react-native: 0.60.4 => 0.60.4 
  npmGlobalPackages:
    create-react-native-app: 1.0.0
    react-native-cli: 2.0.1
    react-native-git-upgrade: 0.2.7

Library version: "react-native-push-notification": "^3.5.1",

Dallas62 commented 4 years ago

Hi @wmonecke

Does that occure every time ? or only in some users ?

zkerkeb commented 4 years ago

Hi, I have the same Issue, after updating my phone to android 10, it's happening for local notifications, don't know what is causing this.

Dallas62 commented 4 years ago

Hi @hikkary This is probably a deprecation in the Android SDK, will take a look at it.

Dallas62 commented 4 years ago

Can someone share the logic that define the date ? If the date is set in the past, the notification will trigger instantly (like when the app is opened). This is actually the most relevant root cause since AlarmManager is still OK on Android 29.

wmonecke commented 4 years ago

Hi @wmonecke

Does that occure every time ? or only in some users ?

Hi! This is mainly happening with Android devices. I can't be sure because 90% of my users are Android users.

Can someone share the logic that define the date ? If the date is set in the past, the notification will trigger instantly (like when the app is opened). This is actually the most relevant root cause since AlarmManager is still OK on Android 29.

This is not the issue. I actually had the issue that the notification fired right away if set on the same date but earlier than the current time. I set the date to the next day if the user schedules a day for the current day but for an earlier hour. Something like this:

if (notificationDate.isBefore(moment())) {
    notificationDate.add(1, 'days')
}

The current issue is different and has happened many times. You won’t receive the notification at the time you set them but once you open the app in the future you will receive ALL scheduled notifications at once.

So for example, if you schedule notifications for 6 pm, 7 pm, and 8 pm, then by 9 pm you won't have received any notification. However, if you open the app at 9 pm you will get all 3.

Dallas62 commented 4 years ago

Can you share the code when you plan the notification ? (parameters) And the AndroidManifest ?

The example project doesn't have this issue even with API 29.

I need a reproducible example to investigate.

wmonecke commented 4 years ago

@Dallas62 Yes of course 👍

Schedule Notification:

PushNotification.localNotificationSchedule({
              /* Android Only Properties */
              id: generatedId, // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
              // largeIcon: "@mipmap/ic_notif", // (optional) default: "ic_launcher"
              smallIcon: "@mipmap/ic_notif", // (optional) default: "ic_notification" with fallback for "ic_launcher"
              vibrate: true, // (optional) default: true
              vibration: 300, // vibration length in milliseconds, ignored if vibrate=false, default: 1000
              priority: "high", // (optional) set notification priority, default: high
              visibility: "public", // (optional) set notification visibility, default: private
              importance: "high", // (optional) set notification importance, default: high
              allowWhileIdle: true, // (optional) set notification to work while on doze, default: false
              ignoreInForeground: false, // (optional) if true, the notification will not be visible when the app is in the foreground (useful for parity with how iOS notifications appear)

              /* iOS only properties */
              alertAction: "view", // (optional) default: view
              userInfo: {
                id: generatedId, // number
              }, // (optional) default: {} (using null throws a JSON value '<null>' error)

              /* iOS and Android properties */
              date: new Date(notificationDate.valueOf()),
              repeatType: 'week',
              message: strings.RoutineComponent.notificationDescription,
              title: routine.title,
            });

Android Manifest:

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

    <uses-permission android:name="android.permission.VIBRATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="com.android.vending.BILLING"/>
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>  
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>     
    <uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION"/>

    <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:allowBackup="true"
      android:theme="@style/AppTheme">

      <!-- BUGSNAG -->
      <meta-data 
        android:name="com.bugsnag.android.API_KEY"
        android:value=""/>
      <meta-data 
        android:name="com.bugsnag.android.DETECT_NDK_CRASHES"
        android:value="true"/>

      <!-- GOOGLE ADS -->
      <meta-data
        android:name="com.google.android.gms.ads.APPLICATION_ID"
        android:value=""/>

      <!-- GOOGLE MAPS -->
      <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value=""/>

      <!-- REACT NATIVE PUSH NOTIFICATION -->
      <meta-data 
        android:name="com.dieam.reactnativepushnotification.notification_channel_name"
        android:value="  {...name} "/>                
      <meta-data 
        android:name="com.dieam.reactnativepushnotification.notification_channel_description"
        android:value=" {...description} "/>

      <!-- Change the value to true to enable pop-up for in foreground (remote-only, for local use ignoreInForeground) -->
      <meta-data 
        android:name="com.dieam.reactnativepushnotification.notification_foreground"
        android:value="true"/>
      <!-- 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 -->

      <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.RNPushNotificationListenerService"
        android:exported="false" >
        <intent-filter>
          <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
      </service>

      <!-- MAIN ACTIVITY -->
      <activity
        android:name=".MainActivity"
        android:launchMode="singleTop"
        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" />
    </application>
</manifest>

android/app/build.gradle

apply plugin: "com.android.application"

import com.android.build.OutputFile

project.ext.react = [
    enableHermes: true,
    entryFile: "index.js",
    //bundleCommand: "ram-bundle",
]

apply from: "../../node_modules/react-native/react.gradle"
apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"

def enableSeparateBuildPerCPUArchitecture = false

def enableProguardInReleaseBuilds = false

def jscFlavor = 'org.webkit:android-jsc:+'

def enableHermes = project.ext.react.get("enableHermes", false);

// Hermes issue with .aab - Reference: https://github.com/facebook/react-native/issues/26400
// configurations.all {
//     resolutionStrategy {
//         force "com.facebook.soloader:soloader:0.8.0"
//     }
// }

android {
    compileSdkVersion rootProject.ext.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId "com.myapp"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        vectorDrawables.useSupportLibrary = true
        renderscriptTargetApi 23
        renderscriptSupportModeEnabled true
        versionCode 68
        versionName "4.6"
        multiDexEnabled true
    }
    dexOptions {
        jumboMode true
        incremental true
        javaMaxHeapSize "4g"
    }
    signingConfigs {
        release {
            if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
                storeFile file(MYAPP_RELEASE_STORE_FILE)
                storePassword MYAPP_RELEASE_STORE_PASSWORD
                keyAlias MYAPP_RELEASE_KEY_ALIAS
                keyPassword MYAPP_RELEASE_KEY_PASSWORD
            }
        }

        debug {
            if (project.hasProperty('MYAPP_DEBUG_STORE_FILE')) {
                storeFile file(MYAPP_DEBUG_STORE_FILE)
                storePassword MYAPP_DEBUG_STORE_PASSWORD
                keyAlias MYAPP_DEBUG_KEY_ALIAS
                keyPassword MYAPP_DEBUG_KEY_PASSWORD
            }
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }
    }
    buildTypes {
        release {
            signingConfig signingConfigs.release
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }

    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
            def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3, "x86_64": 4]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
        }
    }

    packagingOptions {
        pickFirst '**/armeabi-v7a/libc++_shared.so'
        pickFirst '**/x86/libc++_shared.so'
        pickFirst '**/arm64-v8a/libc++_shared.so'
        pickFirst '**/x86_64/libc++_shared.so'
        pickFirst '**/x86/libjsc.so'
        pickFirst '**/armeabi-v7a/libjsc.so'
    }
}

dependencies { 
    // enabling multiDex for minSdkVersion below 20 (current is 16)
    implementation 'androidx.multidex:multidex:2.0.1'

    // react-native
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.facebook.react:react-native:+"  // From node_modules

    // 3rd party
    implementation project(':rn-fetch-blob')
    implementation project(':react-native-fs')
    implementation project(':react-native-svg')
    implementation project(':react-native-video')
    implementation project(':react-native-share')
    implementation project(':lottie-react-native')
    implementation project(':bugsnag-react-native')
    implementation project(':react-native-location')
    implementation project(':react-native-purchases')
    implementation project(':react-native-view-shot')
    implementation project(':react-native-keep-awake')
    implementation project(':react-native-fast-image')
    implementation project(':react-native-date-picker')
    implementation project(':react-native-device-info')
    implementation project(':react-native-vector-icons')
    implementation project(':react-native-localization')
    implementation project(':react-native-splash-screen')
    implementation project(':react-native-google-places')
    implementation project(':react-native-linear-gradient')
    implementation project(':@react-native-community_blur')
    implementation project(':react-native-image-crop-picker')
    implementation project(':react-native-push-notification')
    implementation project(':@react-native-community_google-signin')
    implementation project(':@react-native-community_async-storage')

    // react-native-router-flux
    implementation project(':react-native-screens')
    implementation project(':react-native-reanimated')
    implementation project(':react-native-gesture-handler')
    implementation project(':react-native-safe-area-context')
    implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
    implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha02'

    // react-native-firebase
    implementation project(':react-native-firebase')
    implementation "com.google.android.gms:play-services-base:16.0.1"
    // implementation 'com.google.firebase:firebase-analytics:17.0.1'
    implementation 'com.google.firebase:firebase-analytics:17.3.0'
    implementation 'com.google.firebase:firebase-core:17.0.1'
    implementation "com.google.firebase:firebase-database:17.0.0"
    implementation 'com.google.firebase:firebase-auth:18.1.0'
    implementation "com.google.firebase:firebase-storage:17.0.0"
    implementation 'com.google.firebase:firebase-firestore:20.2.0'
    implementation "com.google.firebase:firebase-ads:18.1.1"
    // implementation "com.google.firebase:firebase-messaging:19.0.1"
    implementation 'me.leolin:ShortcutBadger:1.1.21@aar'
    implementation "com.google.android.gms:play-services-location:16.0.0"

    if (enableHermes) {
      def hermesPath = "../../node_modules/hermesvm/android/";
      debugImplementation files(hermesPath + "hermes-debug.aar")
      releaseImplementation files(hermesPath + "hermes-release.aar")
    } else {
      implementation jscFlavor
    }
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

apply plugin: 'com.google.gms.google-services'

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
Dallas62 commented 4 years ago

Were you able to reproduce it ? Or just user's report ?

I will test on a device tomorrow, I don't see anything that should block (Android Guidelines, Stack Overflow). You are running the task every week, maybe it's related to that (reboot ? too long for the system ? some energy / doze mode kill the app ?)

Do you see a kind of device in report or Android version to find something in common between users ?

wmonecke commented 4 years ago

@Dallas62 I am not able to reproduce it.

It seems the first few notifications work well and it starts sometime in the future. All my users tell me they have allowed all possible permissions (batter manager, etc.) and that it still happens. I don't see any errors or crashes in my logs which is pretty weird.

Dallas62 commented 4 years ago

Hi @wmonecke

Wasn't able to reproduce it actually, but I think one of my application as this kind of bug. I need to find something in common between Android to know where to look.

Maybe reboot, low battery or Android system which kill the alarm manager.

zwenza commented 4 years ago

I am getting same reports from my Android users, but I also couldn't find a way to reproduce yet! Some users receive the notifications only when they open the app.

Will keep you updated if I can find a way to reproduce this.

One thing that I once could see is that low battery caused the app to not send notifications anymore on a friends phone, maybe its related to that?

zwenza commented 4 years ago

Also just received a report that it happened to a user after updating the phone

Dallas62 commented 4 years ago

Hi @zwenza Do you have some information on devices ? Like manufacturers, Android Version and maybe the model could help.

zwenza commented 4 years ago

@Dallas62 I gathered some informations about users who have this problem and you can see a very clear trend:

One user reported it happened after upgrading to Android 10.

Also getting reports about the issue from people with a Samsung Galaxy S7 edge, Samsung Galaxy S9, Samsung Galaxy A50, Samsung Galaxy J7 Prime 2, Samsung Galaxy A51, Samsung Galaxy A20.

So seems that the Samsung Galaxy phones are the ones causing the trouble...

phan21 commented 4 years ago

@Dallas62 I don't think the problem is with the Android update. I haven't received any update for my old Elephone S7 (Android 7.1.1) for years and it doesn't work. All other devices work...

Dallas62 commented 4 years ago

Hi @phan21 Good to hear you are able to reproduce this issue, can tou share the AndroidManifest of your App ?

I will recheck from scratch how this is working, there is probably information in stackoverflow or specialized forum.

phan21 commented 4 years ago

Of course. But my manifest is almost the same as in the example on github here

Hope it helps manifest.txt

ViniciusGularte commented 4 years ago

Same problem here, using a Samsung M30 Android 10, all notifications came after user enter the app

Dallas62 commented 4 years ago

Just to be sure that tis is a "library issue" are you sure that the notifications was scheduled before the app start ? Then do you know if this behavior appear after a restart / reboot or always ?

wmonecke commented 4 years ago

Yes! The notification time is set correctly and the notif should have fired before opening the app. I am experiencing this currently on my personal Xiaomi phone.

All the best and stay safe,

Walter Monecke software engineer @ urban hero

On Tue, Aug 18, 2020, 23:19 Boris Tacyniak notifications@github.com wrote:

Just to be sure that tis is a "library issue" are you sure that the notifications was scheduled before the app start ? Then do you know if this behavior appear after a restart / reboot or always ?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/zo0r/react-native-push-notification/issues/1574#issuecomment-675726012, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFZB7VMQXPUQMEDYBD2KLPDSBLV6NANCNFSM4PRW2K5Q .

wmonecke commented 4 years ago

Here is a video:

https://streamable.com/fkks03

Dallas62 commented 4 years ago

This video is using the options like in the comment: https://github.com/zo0r/react-native-push-notification/issues/1574#issuecomment-669255696 allowWhileIdle: true ?

If yes, do you see the notification pop-up in the next 24h without openning the application ?

I will take time today on this.

wmonecke commented 4 years ago

@Dallas62 Yes it has allowWhileIdle: true just like in my comment above.

If yes, do you see the notification pop-up in the next 24h without openning the application ?

I will test this out today and let you know :)

Thank you for your hard work!

Dallas62 commented 4 years ago

I will link some threads with possible workarounds, since I'm not able to reproduce this, I try to find workaround without editing library at first:

https://stackoverflow.com/questions/35380310/alarmmanager-not-working-on-samsung-devices-in-lollipop

The only way to "fix" this is to inform the Users of your app about the situation and show them how to whitelist your app in Smart Manager. We've had to setup a website with step-by-step instructions showing how to do this for our users.

https://stackoverflow.com/questions/34074955/android-exact-alarm-is-always-3-minutes-off/34085645#340856457 https://issuetracker.google.com/issues/37070267

Edit: Looks like this issue does not occur when there is keyword "alarm" or "alert" in the app package name

Need changes in library:

https://stackoverflow.com/questions/35915326/how-to-schedule-alarm-without-alarmmanager-api

Replace AlarmManager by JobScheduler => time is inexact.

As far as I search, rename the app package seems to be the best solution. Will see if this is working, then find if a workaround with code is possible. Rename the package is really breaking.

https://developer.android.com/studio/build/application-id

Every Android app has a unique application ID that looks like a Java package name, such as com.example.myapp. This ID uniquely identifies your app on the device and in Google Play Store. If you want to upload a new version of your app, the application ID (and the certificate you sign it with) must be the same as the original APK—if you change the application ID, Google Play Store treats the APK as a completely different app. So once you publish your app, you should never change the application ID.

Maybe a application-variant could work...

Dallas62 commented 4 years ago

Does someone able to test the workaround with the application id ? For testing purposes only, expect if your application is not released yet 😅

zwenza commented 4 years ago

Was just looking through your shared link https://stackoverflow.com/questions/34074955/android-exact-alarm-is-always-3-minutes-off/34085645#340856457

image

Can anyone test if simply adding a package containing alarm fixes the issue or if the Samsung Smart Manager kills everything that doesn't have alarm in the application-id?

If changing the application id is the only way this can work, it would be really terrible 😅

Dallas62 commented 4 years ago

I think if this is only package name, this is "not" a problem. I read somewhere that application id and package can be different in AndroidManifest.

But without a test, it's hard to know...

wmonecke commented 4 years ago

@Dallas62 Hi there! I waited 24H but no notification appeared sadly. I had to open the app for it to show :(

daheeahn commented 4 years ago

I faced same issue. @Dallas62 How is it going?

Dallas62 commented 4 years ago

The issue is stuck, waiting for tests described above.

usmansbk commented 3 years ago

@Dallas62 you mean add alarm to the application ID and test?

Dallas62 commented 3 years ago

I'not able to reproduce this issue, follow recommendation in stackoverflow link.

wmonecke commented 3 years ago

I am going to report back if I see any change of behavior on Android 11.

Ajmal0197 commented 3 years ago

I am getting this issue on my redmi device. Schedule notification is coming fine when app is in background if the scheduled time is less but for eg if scheduled time is more like 8 min notification comes only on opening app.

Ajmal0197 commented 3 years ago

I am getting this issue on my redmi device. Schedule notification is coming fine when app is in background if the scheduled time is less but for eg if time schedule time is more like 8 min notification comes only on opening app.

By going to app settings and giving No restriction to battery optimization it got resolved.

usmansbk commented 3 years ago

I am getting this issue on my redmi device. Schedule notification is coming fine when app is in background if the scheduled time is less but for eg if time schedule time is more like 8 min notification comes only on opening app.

By going to app settings and giving No restriction to battery optimization it got resolved.

I just tested it and it works with "No restriction" just like how I fixed notification sound from app settings

raphaelrupprecht commented 3 years ago

Totally agree to @Ajmal0197 and @usmansbk. I am struggling with local notifications for month now. There are a lot of manufacturers who aim energy saving over Android functionality. See https://dontkillmyapp.com/problem. Swiping apps away in the "running apps overview" results in force-close on Xiaomi Mi 9T for example. App auto-starts are restricted after reboot to save energy too. Maybe the Android Team will react on this in Android 12, see https://github.com/notifee/react-native-notifee/issues/126#issuecomment-700736571.

Vadimienne commented 3 years ago

@raphaelrupprecht same story, a tough month trying to find a solution. I'm so happy I've found this thread though. I have the exact same problem testing notifications on my Xiaomi Poco F1. I did some digging into native documentation and here is what I found out: There are two classes used in process of creating a notification NotificationCompat is responsible for notification itself. NotificationChannel is responsible for notification channels.

Here is a priority setter for notification doc reference. https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder#setPriority(int) It says here that notification priority is only still used on older versions of Android.

And an importance setter for notification channel. https://developer.android.com/reference/android/app/NotificationChannel#setImportance(int) Now it is a primary way to set a notification priority. All notifications using particular channel are going to have this channel's importance level. (You can also see here that importance is scaled from 0 to 4/5. React-native-push-notification docs are not clear about possible values, it only says that 4 is default)

So there is a value of 5 that can represent channel importance. Tho it is marked as "unused" in the docs I tried to use it and... got the same result.

Scheduled notifications only work when time offset is really small e.g. <1min. Guess it's just because system doesn't shut down the app right away when you swipe it off recent apps screen. There is some delay.

And it seems confusing because apps with cloud notification services e.g. Firebase work flawlessly.

Finally to the interesting part I installed To Do app from Play Store. Turned on Airplane mode on my phone just to be sure there is no Firebase involved, and scheduled a task for 10 minutes from now. Exited app, closed it in recents. After a few minutes I checked this app out in the Settings. Button "Force stop" wasn't active so I guess system took care of stopping the app after I closed it. And after 10 minutes, I got notification, just in time. So, think there is hope. There is defenitely a way to schedule a notification (or schedule a job to pop a notification) I'll continue to research and let you know if I find anything.

raphaelrupprecht commented 3 years ago

For me all notifications seem to be working when I disable power savings and enable auto-start (or whatever it is called by the vendor). Comparing with "big apps" does sometimes not work. because the device-vendors have white-lists for these apps.

Vadimienne commented 3 years ago

@raphaelrupprecht Well, I'm sad to say that there is seems to be a whitelist of big apps. I've tested a couple of small to do lists and reminders. Just the same behaviour as my app - I only get a reminder notification when I open the app. It's sad that there is no API to ask user for permission to run the app in the background. And your solution is really the one possible workaround a dev can do. Or either write on the MIUI forum for the devs to review your app and add it to the white list. Well, screw it ¯_(ツ)_/¯

Dallas62 commented 3 years ago

Hi @Vadimienne, Are you able to test: https://github.com/zo0r/react-native-push-notification/issues/1574#issuecomment-676043427 This doesn't solve already deployed application, but maybe a solution for application not published yet.

Vadimienne commented 3 years ago

@Dallas62 I completely missed this comment. Laughed as I read about this "alarm/alert" issue and laughed as I tested it. Didn't work for me. And just to mention: I also tested "alarm/alert" in notificaiton channel name and id. Same result.

The guy has Samsung and I have Xiaomi. And the problem is definitely on side of manufacturers power saving policies, and it's just Samsung weird feature that it white-lists "alarms" and "alerts". I'll just stick with disabling power saving for my app. Mainly because app works on other devices as expected without any tweaking.

usmansbk commented 3 years ago

@Vadimienne I guess the best solution is to add a help that links to this dontKillMyApp site

Vadimienne commented 3 years ago

Yes, I think so too @usmansbk 😅

RNTop commented 3 years ago

So Yes, the notification does not working on quit status. so that it will work once I put the app unmonitted apps on device settings. To solve this problem, I would like you to add foreground service in this library. then it will work well. Of course I saw your commit that working on quite status. but it is just on emulator. actually all the notifications libraries working on emulator because it's has unlimitted power.

gargacharya commented 3 years ago

I have also faced this issue on my Xiaomi android phone but after disabling the battery optimization for my phone I am able to get the scheduled notifications.

abhineetsharmathegreat commented 3 years ago

Facing the same issue. When the app is closed and also removed from recent item then the scheduled notification does not appear and only after opening the app, I receive the notification. And if it is left in recent items then the notification appears on correct time. Tried removing battery optimisation for the app and then also the notification does not appear. My android version is 9 and device is Asus Zenfone Max Pro M1. Any suggestions are most welcomed. Thanks

Hermanyo commented 3 years ago

@Dallas62 Yes of course 👍

Schedule Notification:

PushNotification.localNotificationSchedule({
              /* Android Only Properties */
              id: generatedId, // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
              // largeIcon: "@mipmap/ic_notif", // (optional) default: "ic_launcher"
              smallIcon: "@mipmap/ic_notif", // (optional) default: "ic_notification" with fallback for "ic_launcher"
              vibrate: true, // (optional) default: true
              vibration: 300, // vibration length in milliseconds, ignored if vibrate=false, default: 1000
              priority: "high", // (optional) set notification priority, default: high
              visibility: "public", // (optional) set notification visibility, default: private
              importance: "high", // (optional) set notification importance, default: high
              allowWhileIdle: true, // (optional) set notification to work while on doze, default: false
              ignoreInForeground: false, // (optional) if true, the notification will not be visible when the app is in the foreground (useful for parity with how iOS notifications appear)

              /* iOS only properties */
              alertAction: "view", // (optional) default: view
              userInfo: {
                id: generatedId, // number
              }, // (optional) default: {} (using null throws a JSON value '<null>' error)

              /* iOS and Android properties */
              date: new Date(notificationDate.valueOf()),
              repeatType: 'week',
              message: strings.RoutineComponent.notificationDescription,
              title: routine.title,
            });

Android Manifest:

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

    <uses-permission android:name="android.permission.VIBRATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="com.android.vending.BILLING"/>
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>  
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>     
    <uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION"/>

    <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:allowBackup="true"
      android:theme="@style/AppTheme">

      <!-- BUGSNAG -->
      <meta-data 
        android:name="com.bugsnag.android.API_KEY"
        android:value=""/>
      <meta-data 
        android:name="com.bugsnag.android.DETECT_NDK_CRASHES"
        android:value="true"/>

      <!-- GOOGLE ADS -->
      <meta-data
        android:name="com.google.android.gms.ads.APPLICATION_ID"
        android:value=""/>

      <!-- GOOGLE MAPS -->
      <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value=""/>

      <!-- REACT NATIVE PUSH NOTIFICATION -->
      <meta-data 
        android:name="com.dieam.reactnativepushnotification.notification_channel_name"
        android:value="  {...name} "/>                
      <meta-data 
        android:name="com.dieam.reactnativepushnotification.notification_channel_description"
        android:value=" {...description} "/>

      <!-- Change the value to true to enable pop-up for in foreground (remote-only, for local use ignoreInForeground) -->
      <meta-data 
        android:name="com.dieam.reactnativepushnotification.notification_foreground"
        android:value="true"/>
      <!-- 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 -->

      <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.RNPushNotificationListenerService"
        android:exported="false" >
        <intent-filter>
          <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
      </service>

      <!-- MAIN ACTIVITY -->
      <activity
        android:name=".MainActivity"
        android:launchMode="singleTop"
        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" />
    </application>
</manifest>

android/app/build.gradle

apply plugin: "com.android.application"

import com.android.build.OutputFile

project.ext.react = [
    enableHermes: true,
    entryFile: "index.js",
    //bundleCommand: "ram-bundle",
]

apply from: "../../node_modules/react-native/react.gradle"
apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"

def enableSeparateBuildPerCPUArchitecture = false

def enableProguardInReleaseBuilds = false

def jscFlavor = 'org.webkit:android-jsc:+'

def enableHermes = project.ext.react.get("enableHermes", false);

// Hermes issue with .aab - Reference: https://github.com/facebook/react-native/issues/26400
// configurations.all {
//     resolutionStrategy {
//         force "com.facebook.soloader:soloader:0.8.0"
//     }
// }

android {
    compileSdkVersion rootProject.ext.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId "com.myapp"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        vectorDrawables.useSupportLibrary = true
        renderscriptTargetApi 23
        renderscriptSupportModeEnabled true
        versionCode 68
        versionName "4.6"
        multiDexEnabled true
    }
    dexOptions {
        jumboMode true
        incremental true
        javaMaxHeapSize "4g"
    }
    signingConfigs {
        release {
            if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
                storeFile file(MYAPP_RELEASE_STORE_FILE)
                storePassword MYAPP_RELEASE_STORE_PASSWORD
                keyAlias MYAPP_RELEASE_KEY_ALIAS
                keyPassword MYAPP_RELEASE_KEY_PASSWORD
            }
        }

        debug {
            if (project.hasProperty('MYAPP_DEBUG_STORE_FILE')) {
                storeFile file(MYAPP_DEBUG_STORE_FILE)
                storePassword MYAPP_DEBUG_STORE_PASSWORD
                keyAlias MYAPP_DEBUG_KEY_ALIAS
                keyPassword MYAPP_DEBUG_KEY_PASSWORD
            }
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }
    }
    buildTypes {
        release {
            signingConfig signingConfigs.release
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }

    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
            def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3, "x86_64": 4]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
        }
    }

    packagingOptions {
        pickFirst '**/armeabi-v7a/libc++_shared.so'
        pickFirst '**/x86/libc++_shared.so'
        pickFirst '**/arm64-v8a/libc++_shared.so'
        pickFirst '**/x86_64/libc++_shared.so'
        pickFirst '**/x86/libjsc.so'
        pickFirst '**/armeabi-v7a/libjsc.so'
    }
}

dependencies { 
    // enabling multiDex for minSdkVersion below 20 (current is 16)
    implementation 'androidx.multidex:multidex:2.0.1'

    // react-native
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.facebook.react:react-native:+"  // From node_modules

    // 3rd party
    implementation project(':rn-fetch-blob')
    implementation project(':react-native-fs')
    implementation project(':react-native-svg')
    implementation project(':react-native-video')
    implementation project(':react-native-share')
    implementation project(':lottie-react-native')
    implementation project(':bugsnag-react-native')
    implementation project(':react-native-location')
    implementation project(':react-native-purchases')
    implementation project(':react-native-view-shot')
    implementation project(':react-native-keep-awake')
    implementation project(':react-native-fast-image')
    implementation project(':react-native-date-picker')
    implementation project(':react-native-device-info')
    implementation project(':react-native-vector-icons')
    implementation project(':react-native-localization')
    implementation project(':react-native-splash-screen')
    implementation project(':react-native-google-places')
    implementation project(':react-native-linear-gradient')
    implementation project(':@react-native-community_blur')
    implementation project(':react-native-image-crop-picker')
    implementation project(':react-native-push-notification')
    implementation project(':@react-native-community_google-signin')
    implementation project(':@react-native-community_async-storage')

    // react-native-router-flux
    implementation project(':react-native-screens')
    implementation project(':react-native-reanimated')
    implementation project(':react-native-gesture-handler')
    implementation project(':react-native-safe-area-context')
    implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
    implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha02'

    // react-native-firebase
    implementation project(':react-native-firebase')
    implementation "com.google.android.gms:play-services-base:16.0.1"
    // implementation 'com.google.firebase:firebase-analytics:17.0.1'
    implementation 'com.google.firebase:firebase-analytics:17.3.0'
    implementation 'com.google.firebase:firebase-core:17.0.1'
    implementation "com.google.firebase:firebase-database:17.0.0"
    implementation 'com.google.firebase:firebase-auth:18.1.0'
    implementation "com.google.firebase:firebase-storage:17.0.0"
    implementation 'com.google.firebase:firebase-firestore:20.2.0'
    implementation "com.google.firebase:firebase-ads:18.1.1"
    // implementation "com.google.firebase:firebase-messaging:19.0.1"
    implementation 'me.leolin:ShortcutBadger:1.1.21@aar'
    implementation "com.google.android.gms:play-services-location:16.0.0"

    if (enableHermes) {
      def hermesPath = "../../node_modules/hermesvm/android/";
      debugImplementation files(hermesPath + "hermes-debug.aar")
      releaseImplementation files(hermesPath + "hermes-release.aar")
    } else {
      implementation jscFlavor
    }
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

apply plugin: 'com.google.gms.google-services'

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

Did you try to add,

   <meta-data
      android:name="com.dieam.reactnativepushnotification.default_notification_channel_id"
      android:value="@string/default_notification_channel_id" />

in your androidmanifest? And using createChannel method in your code?

janeirojoaopedro commented 3 years ago

any solution ?

yinka1255 commented 3 years ago

I’ve been battling the same issue for a while now. Notification comes only when app is in foreground or background. It does not come when the app is killed