Cordova-plugin-local-notifications: Notification sound and icon on Android

Created on 16 Aug 2016  路  13Comments  路  Source: katzer/cordova-plugin-local-notifications

Hi, there!

I'm having issues with the sound of the notifications, at first I think it vibrated (may be wrong about this), now it does nothing. Here's my code:

var date = '2016-08-11';
var time = '04:16';
var title = 'Test';
var message = 'This is a test';

var schedule_time = new Date((date + " " + time).replace(/-/g, "/")).getTime();
schedule_time = new Date(schedule_time);

window.plugin.notification.local.schedule({
    id:         "1", 
    date:       schedule_time,
    message:    message,
    title:      title,
    sound:      'SYSTEM_DEFAULT',
    icon: 'www/icon.png' //It's a 300x300 icon
    autoCancel: true
});

I've tried putting 'android.resource://' + package_name + '/raw/beep' (beep is stored in www/ and in platforms/android/res/raw), 'android.resource://' + package_name + '/raw/beep.mp3' (just added the .mp3), 'TYPE_ALARM', 'SYSTEM_DEFAULT', 'www/beep.mp3', 'file:///www/beep.mp3', an URL... To no avail, no sound at all. I've tried with the icon too, but less stuff, just the URL and the file path there's in the code I wrote here, just appears a square with rounded corners instead of the bell.

The version I'm using is the 0.8.4, and the Android version is 6.0.1.

Thanks in advance for your help!

Most helpful comment

create a folder in cordova "platforms/android/res/drawable"
copy your icon into it (name must be lower case -- make it "sm_icon.png")
refer to is as "res://sm_icon.png" in notification

All 13 comments

For the icon you should prefix it with file so it looks like so: file://icon.png. You can omit the www part because the file:// protocol automatically adds this. This is documented here on the wiki

@RangerMauve Thanks a lot! The icon is still showing the square, but the notification sound works now without the www.

+1 @RangerMauve Thanks
@Davegb same here. Sounds works but icon displays as square.

why do not set icon?
code: icon: 'file://img/code.png'

if you see a white square and not the default bell, it's most likely because it loads the correct image but it's not in the accepted format.

It should be white with no gradient and it also has some size specs. This should probably be added to the doc somewhere.

https://material.google.com/style/icons.html#

@Davegb How did you fix this issue?
I've tried res://icon.png, file://img/icon.png, res://icon, file://img/icon nothing seems to work.

@iamola I left the default one, the bell, didn't set anything for the icon.

@Davegb Oh wow. Bummer.

@RangerMauve Thanks man, Icon and smallIcon is working charm.

Also see #1222

create a folder in cordova "platforms/android/res/drawable"
copy your icon into it (name must be lower case -- make it "sm_icon.png")
refer to is as "res://sm_icon.png" in notification

Is this still an issue?

Closed as no update from original poster.

Was this page helpful?
0 / 5 - 0 ratings