0

I would like to send an notification with an image within. But in the object properties there is no way to add an image.

Here is the plugin: https://github.com/katzer/cordova-plugin-local-notifications/wiki/05.-Update

Iam wondering if I can modify the notification object to send an image in the local notifications.

Sireini
  • 4,142
  • 12
  • 52
  • 91

1 Answers1

0

You can convert your image to base64 encoded image and then add the encoded image to the notification object.

Here is an example:

var notificationObj = {
   title: "My title goes here",
   description: "My description goes here",
   img:"image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABg....AElFTkSuQmCC" //this is the base64 encoded image
}

//Schedule the notification code goes here

Then you would be able to access that base64 encoded image when the notification fires

cordova.plugins.notification.local.on("click", function (notification) {
    //The property notification.data.img now contains the base64 encoded image and
    // you can use it directly as a source for <img> tag. Example:

   document.getElementById("myImage").src= notification.data.img ;
});
Dola
  • 1,483
  • 11
  • 16
  • How would you do that? I used this online converter: https://www.base64-image.de/ But I dont know what to include in the messgae of the notification? The html or what? – Sireini Nov 16 '16 at 14:20
  • I tried it with this output: http://www.dailycoding.com/Utils/Converter/ImageToBase64.aspx. But it only shows me the output as a string – Sireini Nov 16 '16 at 14:47
  • That's the point, you convert the image into base64 encoded string so that you can store it in the notification object. Then when the user clicks the notification, it's retrieved in the notification object as string and you can then use it as you like. – Dola Nov 16 '16 at 17:32