Reputation: 1303
I'am using Cordova LocalNotification-Plugin to show some notification to user . Now what I want to do is to have a specific sound on notification . They said to add this
window.plugin.notification.local.add({ sound: 'android.resource://' + package_name +/raw/beep});
Note: Local sound files must be placed into the res-folder and not into the assets-folder.
I don't know in which res folder should I put my mp3. And if I try to put it into main res folder where I have : drawable; drawable-hdpi; drawable-ldpi;drawable-mdpi;drawable-xhdpi;values;xml folders when I build the project I get this error:
invalid resource directory name: C:\Users\etc\etc\myprojectname\platforms\android\res/sounds
What should I do ?
Upvotes: 3
Views: 4768
Reputation: 8025
Yes you are right you should just create the missing var and assign your package name (the one you use when created the phonegap/cordova project with the command line something like this for example:
cordova create LocalNotification com.example.localnotification LocalNotification
Should be used in the plugin with these values:
var package_name = "com.example.localnotification";
window.plugin.notification.local.add({
date : Math.round(new Date().getTime()/1000 + 5),
title : "Android App Tes Local Notification",
message : "This is a new local notification.",
repeat : "daily",
sound : 'android.resource://' + package_name + '/raw/beep',
badge : 0,
id : 666,
foreground : function(notificationId){
console.log("Hello World! This alert was triggered by notification " + notificationId);
},
background : function(notificationId){
console.log("Hello World! This alert was triggered by notification " + notificationId);
}
});
And just in case someone is interested on creating local notifications for android this is absolutely beautiful and working just fine!
Download local notification plugin (working on Android ONLY)
Upvotes: 1
Reputation: 11721
As I understand it, you should put your sound file in the res/raw folder instead of res/sounds (as you see in the plugin call : +/raw/beep).
There is no /res/sounds folder in android, datas that do not fit in other categories should be put in /res/raw. You can have a look at the sdk doc
Upvotes: 2