How to add resources file to my phonegap project

混江龙づ霸主 提交于 2019-12-05 03:32:24

问题


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 ?


回答1:


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




回答2:


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)

Download beep.mp3



来源:https://stackoverflow.com/questions/21053096/how-to-add-resources-file-to-my-phonegap-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!