Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notifications appear ONLY after opening the app! #1574

Open
wmonecke opened this issue Aug 1, 2020 · 74 comments
Open

Notifications appear ONLY after opening the app! #1574

wmonecke opened this issue Aug 1, 2020 · 74 comments
Assignees

Comments

@wmonecke
Copy link

wmonecke commented Aug 1, 2020

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
Copy link
Collaborator

Dallas62 commented Aug 3, 2020

Hi @wmonecke

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

@zkerkeb
Copy link

zkerkeb commented Aug 5, 2020

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
Copy link
Collaborator

Dallas62 commented Aug 5, 2020

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

@Dallas62 Dallas62 self-assigned this Aug 5, 2020
@Dallas62
Copy link
Collaborator

Dallas62 commented Aug 5, 2020

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
Copy link
Author

wmonecke commented Aug 5, 2020

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
Copy link
Collaborator

Dallas62 commented Aug 5, 2020

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
Copy link
Author

wmonecke commented Aug 5, 2020

@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
Copy link
Collaborator

Dallas62 commented Aug 5, 2020

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 ?

@Dallas62 Dallas62 pinned this issue Aug 5, 2020
@wmonecke
Copy link
Author

wmonecke commented Aug 8, 2020

@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
Copy link
Collaborator

Dallas62 commented Aug 8, 2020

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
Copy link

zwenza commented Aug 15, 2020

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
Copy link

zwenza commented Aug 16, 2020

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

@Dallas62
Copy link
Collaborator

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

@zwenza
Copy link

zwenza commented Aug 18, 2020

@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
Copy link

phan21 commented Aug 18, 2020

@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
Copy link
Collaborator

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
Copy link

phan21 commented Aug 18, 2020

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

Hope it helps
manifest.txt

@ViniciusGularte
Copy link

ViniciusGularte commented Aug 18, 2020

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

@Dallas62
Copy link
Collaborator

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
Copy link
Author

wmonecke commented Aug 18, 2020 via email

@wmonecke
Copy link
Author

Here is a video:

https://streamable.com/fkks03

@Dallas62
Copy link
Collaborator

This video is using the options like in the comment: #1574 (comment)
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
Copy link
Author

@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
Copy link
Collaborator

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
Copy link
Collaborator

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

@zwenza
Copy link

zwenza commented Aug 21, 2020

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
Copy link
Collaborator

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
Copy link
Author

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

@abhineetsharmathegreat
Copy link

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
Copy link

Hermanyo commented Apr 10, 2021

@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
Copy link

any solution ?

@yinka1255
Copy link

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

@wmonecke
Copy link
Author

wmonecke commented May 15, 2021

@Hermanyo

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?

I have used both. This has nothing to do with the notification channel but with the OS suppressing notifications. If I go into settings and apply "No restrictions" in regards to battery consumption, it works as expected.

Currently, I implemented a FAQ in my app that tells the user what to do in case the notifications are not arriving. Not the ideal. Let's just hope vendors stop with this practice.

If notifications (specifically locally scheduled notifications) are mission critical for your app then I recommend you take the (android) user to settings and disable any restrictions during your app onboarding.

@Dallas62
Copy link
Collaborator

Hi @wmonecke
Any reason to not use something like "remote scheduled notification" ?
Regards

@sanchitdaffodil
Copy link

I am able to reproduce this and what I can debug that debugger hits notificationManager.notify(notificationID, info); under RNPushNotificationHelper.java , It detects the notifications correctly but looks it doesn't show that on notification bar

@Balthazar33
Copy link

Balthazar33 commented May 30, 2021

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

Had the same problem but it seems to be working now after I added:

allowWhileIdle: true,
and

importance:Importance.HIGH

in PushNotification.localNotificationSchedule
Android version : 10
Device: Nokia

@usmansbk
Copy link

@Balthazar33 Wow! You solution worked perfectly on my Xiaomi device. Although TypeScript keeps saying it's incompatible. But it works. Thanks!

@bostnis
Copy link

bostnis commented Jun 10, 2021

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.

Thanks for your thread!

@roryabraham
Copy link

I'm experiencing this with local notifications on iOS and react-native-push-notification ^7.3.1

@Lekhrajk
Copy link

Lekhrajk commented Jul 8, 2021

I'm experiencing this with local notifications on iOS and react-native-push-notification ^7.3.1

I am also facing same issue any solution for this and could anyone please tell me what is best way to set time for schedule notification

@snowfluke
Copy link

I have 2 Local scheduled notifications every day and it only appear one notifications per day. Yes, the app is in quit mode. I tried to make different channel but seems not working.

@snowfluke
Copy link

I have 2 Local scheduled notifications every day and it only appear one notifications per day. Yes, the app is in quit mode. I tried to make different channel but seems not working.

Update:
The second scheduled notification was fired 6 minutes after the fire date, sometimes more.

@bhumill
Copy link

bhumill commented Jul 14, 2021

hii!
I am facing the same issue. My scheduled notification is not arriving when the app is in background or killed mode and notification arrives when the app is opened. And If I change the scheduled time while the app is in foreground mode the notification arrives immediately and not on scheduled time. Please help!

@sanchitdaffodil
Copy link

sanchitdaffodil commented Jul 14, 2021 via email

@roryabraham
Copy link

In my case, I'm in this kind of scenario with local notifications:

  • I'm creating a local notification when I receive a websocket event via Pusher.
  • This works as expected when the app is in the foreground.
  • When the app is backgrounded, we maintain the websocket connection as long as the OS will allow it. After some indeterminate amount of time, the OS will kill the websocket connection.
  • While the app is backgrounded and Pusher is connected, local notifications work as expected.
  • While the app is backgrounded or closed and Pusher is not connected, local notifications don't appear. That's also expected. (We have a separate implementation for push notifications that works, I'm just trying to get local notifications working for websocket events)
  • However, when the app later reopens and re-establishes the websocket connection, local notifications appear for all of the Pusher events that were missed while the client was disconnected.

I'm looking for a way to avoid this happening, and any suggestions are appreciated! It might honestly be more related to my Pusher implementation than the local notifications themselves, but I'm leaving a comment here in case anyone finds themselves in a similar situation.

@raturiji
Copy link

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

Had the same problem but it seems to be working now after I added:

allowWhileIdle: true,
and

importance:Importance.HIGH

in PushNotification.localNotificationSchedule
Android version : 10
Device: Nokia

The solution you provide is actually worked for me and i get the notification on the second day but i am not getting the notification on the third day as i have implemented the notification for five consecutive days. Also i did not open the app on the second day because i have scheduled the five days notification altogether on first day. Can you give any solution for that ?

@Balthazar33
Copy link

Balthazar33 commented Jul 26, 2021

Had the same problem but it seems to be working now after I added:
allowWhileIdle: true,
and
importance:Importance.HIGH
in PushNotification.localNotificationSchedule
Android version : 10
Device: Nokia

The solution you provide is actually worked for me and i get the notification on the second day but i am not getting the notification on the third day as i have implemented the notification for five consecutive days. Also i did not open the app on the second day because i have scheduled the five days notification altogether on first day. Can you give any solution for that ?

Can you share your code? (for scheduling the notifications)

@raturiji
Copy link

Had the same problem but it seems to be working now after I added:
allowWhileIdle: true,
and
importance:Importance.HIGH
in PushNotification.localNotificationSchedule
Android version : 10
Device: Nokia

The solution you provide is actually worked for me and i get the notification on the second day but i am not getting the notification on the third day as i have implemented the notification for five consecutive days. Also i did not open the app on the second day because i have scheduled the five days notification altogether on first day. Can you give any solution for that ?

Can you share your code? (for scheduling the notifications)

yeah sure below is my code for scheduling daily notifications

for (let i = 0; i < 3; i++) {
const dates = moment(
${moment().add(i, 'day').format('YYYY-MM-DD')} ${ 08:00 },
).toDate();
PushNotification.localNotificationSchedule({
channelId: 'channel-id',
id: i,
title: 'Daily Sample Reminder',
message: Test Daily Reminder,
allowWhileIdle: true,
priority: 'high',
importance: Importance.HIGH,
date: dates,
smallIcon: 'notification_icon',
playSound: true,
});
}

@usmansbk
Copy link

But you didn't specify the repeatType @raturiji

@raturiji
Copy link

But you didn't specify the repeatType @raturiji

Yes because i don't want them to repeat daily instead i want to repeat them for a limited number of days that's why i am using for loop to schedule them for next consecutive days.

@usmansbk
Copy link

usmansbk commented Jul 26, 2021

@raturiji but your loop only iterates twice. So it'll only work for tomorrow and next

@raturiji
Copy link

@raturiji but your loop only iterates twice. So it'll only work for tomorrow and next

No, it is actually running three times for i value 0,1 and 2 which is for today , tomorrow and next

@nghiant96
Copy link

@raturiji it max 64 local push :(

@raturiji
Copy link

@raturiji it max 64 local push :(

Can u explain a little bit ?

@nghiant96
Copy link

nghiant96 commented Aug 19, 2021

@raturiji it max 64 local push :(

Can u explain a little bit ?

I'm doing a lesson reminder function. Almost like an alarm. But on ios, It only gives maximum 64 schedule.
You can edit length to 365 and create push end then getScheduledLocalNotifications

@mohammad-goldast
Copy link

Any solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests