0

phonegap アプリでカスタム サウンドの正しい URI を設定しようとしています。以下を含むいくつかの組み合わせを試しましたが、Uri cannot be resolved

  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 を設定するにはどうすればよいですか

より詳しい情報

このチュートリアルを最後に使用して、プッシュメッセージから通知を追加する方法を説明しています....

  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、カスタムサウンドが配置されると思いました。

4

1 に答える 1

0

それが JavaScript コードの場合、問題はコードと Uri 変数/ライブラリの定義方法にあります。

notificationAPIを使用している場合、デフォルトの「ビープ音」を指定する方法はありません(iOS を除きますが、iOS にはビープ音がないためです)。

特定のサウンドを再生しようとしている場合は、メディア 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 ページを正しく設定する方法については、「完全な例」を参照してください。

于 2013-05-01T15:27:20.100 に答える