Ion 2: local notification icon

I use this plugin for local notification: https://github.com/katzer/cordova-plugin-local-notifications/wiki/03.-Installation

I want to have a specific icon in my notification. It is located in the my / www / assets / images / folder.

I try, but it does not work, I have a square icon with a bell:

public schedule() { cordova.plugins.notification.local.schedule({ title: "New Message", message: "Hi, are you ready? We are waiting.", sound: null, at: new Date(new Date().getTime() + 5 * 1000), icon: 'file://assets/images/logo2.png' }); } 

Can anyone show me the type of path I should write? I am lost.

+5
source share
4 answers

I found a solution:

I create a new folder with the name "drawable" in / platform / android / res / I put my image in my new folder with the names "ic_notifications.png" and "ic_notifications_small.png".

In my code I wrote

 cordova.plugins.notification.local.schedule({ id: 2, title: "Notification", message: "Retour à l'application", sound: null, at: new Date(new Date().getTime() + 5 * 1000), icon: 'ic_notifications', smallIcon: 'ic_notification_small' }); 

And it works!

+1
source

For local push notification of the ionic 2 plugin, you can set the icon as shown below. Here icon.png will be extracted from the drop-down folder in case of android. And you can configure ionic to copy the local image file, which will be copied to the folder with the ability to transfer, adding below in the configuration file in the section of the Android platform.

 <platform name="android"> <resource-file src="resources/android/icon/icon.png" target="res/drawable/icon.png"/> </platform> this.localNotifications.schedule({ id: 1, title: data.title, text: data.body, data: data, icon: "res://icon.png", smallIcon:"res://icon.png" }); 
+4
source

If your only problem is that the notification icons display correctly on Android, it worked for me: use the drawable-xhdpi-icon icon (size 96x96 ), rename it icon.png and put it in two places:

  • / src / assets / img
  • / platforms / Android / res / hood

The drawable folder is a new folder that can be created by copying the platforms / android / res / mipmap -xhdpi to the platforms / android / res / drawable manually or using a hook. In your code, a local or geofence notification is specified as follows:

 smallIcon: 'res://icon', icon: 'file://assets/img/icon.png' 

If ionic cord resources are part of the problem, you can make your own one-time setup by taking your largest icon and using a resizing tool like resizeimage.net, create a set of icons for iOS and Android. In Excel, here https://github.com/dovk/howto_resources-folder there is a list of sizes and names of the generated .png files. Then you put them in the corresponding resources folder, as I would do with ionic cordova resources - for example, in resources / android / icon, resources / ios / splash , etc. If you do, then the ionic cordova platform add android or the addios ionic cordova platform should no longer be used, as it also means the resources of the ionic cordova > - What you need to do is the cordova add platform (without the ionic at the beginning).

+2
source

Indicate the image path below without adding the file name extension LocalNotifications.schedule({ id: 1, title: "Notification Title", text: "Notification Text", icon: 'assets://images/image_name' });

0
source

Source: https://habr.com/ru/post/1263973/


All Articles