How to change Android local notification icon in ionic?

I am using ionic to create an android application. I use $cordovaLocalNotificationfor local notifications. The notification works, but it shows the default bell icon. How to customize the notification icon?

+4
source share
3 answers
$scope.scheduleSingleNotification = function () {
    $cordovaLocalNotification.schedule({
      id: 1,
      title: 'GRM APP Builder',
      text: 'Quer cafΓ©?!?',
      badge: 1,
      icon: 'res://coffee.png',
      data: {
        customProperty: 'custom value 1'
      }
    }).then(function (result) {
      console.log('Notification 1 triggered');
    });
  };

After several hours with this question, I saw that one comment on him was really right.

If you want to change the icon, you need to create a folder called "drawable" in "[folder with ionic app] \ platform \ android \ res \ drawable".

: CLI " - -l -c -s". , .

Android-, iOS, , .

+3

smallIcon. /platform/android/res/drawable/folder. ( , "res://somename" )

. ngCordova, .

+1

ionic-cli 3,

icon.png .

platforms/android/res/drawable/icon.png

, Android.

Once this is done (make sure the image is a transparent icon)

The next step is to initialize this icon in the notification.init function.

Now, if you use push plugin follow these steps:

const pushObj: PushObject = this.push.init({
                        android: {
                            senderID: "your_id",
                            icon: "icon",
                            forceShow: "true"
                        },
                        ios: {
                            alert: "true",
                            badge: "true",
                            sound: "true"
                        }
                    });

As you can see, only the icon name is not extenstion added.

Once this is done, add the same pair of key values ​​to the server-side code that clicks the notification on your device.

Everything will work well.

0
source

All Articles