これに関連する Stackoverflow には少なくとも 7 つの質問があります。すべての提案と解決策を複数回試しましたが、どれも機能しませんでした。これが私の最新の試みです:
private Notification createNotification() {
Notification notification = new Notification();
if(notifyImage=="food")
{
notification.icon = R.drawable.food;
notification.sound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://com.example.memoryGuide/raw/start");
}
else
{
notification.icon = R.drawable.bar;
notification.sound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://com.example.memoryGuide/raw/start");
}
notification.when = System.currentTimeMillis();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.ledARGB = Color.WHITE;
notification.ledOnMS = 1500;
notification.ledOffMS = 1500;
return notification;
}
うまくいかないサウンドを 2 回使用しようとしたことがわかりますが、アイコンは完全に機能します。これを機能させるために何か不足しているかどうかはわかりませんが、使用しているコードはすべて投稿に含まれています。
私のサウンド ファイルは res/raw/start.mp3 にあります。ボタンを押すとこのサウンドが動作するので、サウンドは問題ありません。
パッケージ名は正しいと思います。私のアプリケーションには、各クラスの上部にこれがあります:
package com.example.memoryGuide;
サウンドが再生されない理由はありますか?