katzer / cordova-plugin-local-notifications

Cordova Local-Notification Plugin
Apache License 2.0
2.57k stars 1.76k forks source link

Ionic/Angular Resources$NotFoundException: Drawable android:id/icon #1820

Closed minicatsCB closed 1 month ago

minicatsCB commented 5 years ago

Your Environment

Expected Behavior

  1. Open the app.
  2. Wait for five seconds.
  3. A local notification should appear in the status bar.

Actual Behavior

  1. Open the app.
  2. The app crashes.

Steps to Reproduce

  1. Create a simple Ionic app: ionic start notif sidemenu --type=ionic-angular.
  2. Install Cordova: npm install -g ionic cordova.
  3. Install the Inonic Native wrapper for the plugin following the Ionic documentation: npm install --save @ionic-native/local-notifications@4.
  4. Install the plugin itself: ionic cordova plugin add cordova-plugin-local-notification@0.8.4. If I follow the official Ionic documentation, it installs the beta version 0.9.0-beta-2, but I don't want to use the beta in production, so I choose 0.8.4. (Anyway, with both versions the results are the same).
  5. Add this plugin to your app's module in src/app/app.module.ts.
    
    ...
    import { LocalNotifications } from '@ionic-native/local-notifications';
    ...

... providers: [ StatusBar, SplashScreen, LocalNotifications, {provide: ErrorHandler, useClass: IonicErrorHandler} ] ...

6. Schedule a notification after five seconds after entering the view in `src/pages/home/home.ts`:
```javascript
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';

import { LocalNotifications } from '@ionic-native/local-notifications';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  public isNotificationScheduled = false;

  constructor(public navCtrl: NavController,
              private localNotifications: LocalNotifications) {

  }

  public ionViewDidEnter() {
    this.localNotifications.schedule({
      text: 'Delayed ILocalNotification',
      trigger: {at: new Date(new Date().getTime() + 3600)},
      led: 'FF0000',
      sound: null
    });

    console.log("Notification is scheduled");
    this.isNotificationScheduled = true;
  }

}
  1. (Optional) Add a visual indicator to src/pages/home/home.html. I did this to have something that tells me if the notification has been scheduled.
    <p [ngStyle]="{'background-color': isNotificationScheduled ? 'green' : 'red' }">Notification is scheduled</p>

Context

I'm trying to use this plugin in a bigger project but I can't get it to work. I decided to create a simple Ionic app with minimal code to try to isolate the problem.

Debug logs

matiaslavanchi commented 5 years ago

I had the same problems. It seems the plugins has some trouble with the DEFAULT ICON and the app crashes because of that You have to set de value of smallIcon to an icon that exists. this is your example with added icon. this.localNotifications.schedule({ text: 'Delayed ILocalNotification', trigger: {at: new Date(new Date().getTime() + 3600)}, led: 'FF0000', smallIcon : "res://mipmap-ldpi/ic_launcher.png", sound: null }

rbarriuso commented 5 years ago

Perhaps this is fixed by https://github.com/katzer/cordova-plugin-local-notifications/commit/b8f358ebb9ed76a1ddd61892a66dee1777042bfc

DanielRiera commented 4 years ago

I had the same problems. It seems the plugins has some trouble with the DEFAULT ICON and the app crashes because of that You have to set de value of smallIcon to an icon that exists. this is your example with added icon. this.localNotifications.schedule({ text: 'Delayed ILocalNotification', trigger: {at: new Date(new Date().getTime() + 3600)}, led: 'FF0000', smallIcon : "res://mipmap-ldpi/ic_launcher.png", sound: null }

Yes.