2013-05-01 68 views
0

我正嘗試在phonegap應用程序中爲自定義聲音設置正確的URI。我嘗試了好幾種的組合,包括以下但我不斷收到一個Uri cannot be resolved設置phonegap的通知URI

notif.sound = Uri.parse("android.resource://package_name/raw/notification/alarm.WAV"); 

    notif.sound = Uri.parse("android.resource://package_name/raw/notification/"); 

    notif.sound = Uri.parse("file://path/to/file/alarm.WAV"); 

如何使用PhoneGap的

當我設置的URI健全

更多信息

我使用this tutorial在其結尾部分解釋如何添加來自推送消息的通知....

String message = extras.getString("message"); 
    String title = extras.getString("title"); 
    Notification notif = new Notification(android.R.drawable.btn_star_big_on, message,    System.currentTimeMillis()); 
    notif.flags = Notification.FLAG_AUTO_CANCEL; 
    notif.defaults |= Notification.DEFAULT_SOUND; 
    notif.defaults |= Notification.DEFAULT_VIBRATE; 

    Intent notificationIntent = new Intent(context, TestSampleApp.class); 
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); 
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); 

    notif.setLatestEventInfo(context, title, message, contentIntent); 
    String ns = Context.NOTIFICATION_SERVICE; 
    NotificationManager mNotificationManager = (NotificationManager) 
    context.getSystemService(ns); 
    mNotificationManager.notify(1, notif); 

我認爲刪除Notification.DEFAULT_SOUND;和添加uri將使它發出一個自定義的聲音。

回答

0

如果這是JavaScript代碼,問題出在代碼以及如何定義Uri變量/庫。

如果您使用的是notification API,有沒有辦法來指定default "beep" sound(除iOS的,但那是因爲沒有在iOS嗶聲。)

如果你正在嘗試播放特定聲音,我想你應該使用media API.您可以指定一個聲音這樣玩:

function playAudio(url) { 
    // Play the audio file at url 
    var my_media = new Media(url, 
     // success callback 
     function() { 
      console.log("playAudio():Audio Success"); 
     }, 
     // error callback 
     function(err) { 
      console.log("playAudio():Audio Error: "+err); 
    }); 

    // Play audio 
    my_media.play(); 
} 

看看「全榜樣」,以瞭解如何正確設置HTML頁面。

+0

這是來自推送插件內的java – maxum 2013-05-02 03:24:54

+0

你正在編寫自己的插件嗎?我需要看到更多的代碼,我真的不知道'notif'對象是什麼。 – MBillau 2013-05-02 14:34:31

+0

道歉更多信息的問題 – maxum 2013-05-03 04:13:30