Java 在通知中制作特定歌曲

Java 在通知中制作特定歌曲,java,android,notifications,Java,Android,Notifications,当我收到通知时,是否可以从原始文件夹开始制作歌曲? 我试着用这个代码让歌曲“警报”开始,但什么也没发生 NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(R.drawable.beatdanger,

当我收到通知时,是否可以从原始文件夹开始制作歌曲? 我试着用这个代码让歌曲“警报”开始,但什么也没发生

NotificationManager notificationManager = (NotificationManager) context
        .getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.beatdanger,
        "Your friend is in danger!!!", System.currentTimeMillis());
// Hide the notification after its selected
notification.flags |= Notification.FLAG_AUTO_CANCEL;

notification.sound = Uri.parse("R.raw.alert");


Intent intent1 = new Intent("wael.ilahi.pfe.SMSRECEIVERESULT");
intent1.putExtra("coordination", str);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
        intent1, 0);
notification.setLatestEventInfo(context, "Help your friend !!",
        str, pendingIntent);
notificationManager.notify(0, notification);
请参阅中的“添加声音”一章

您的问题似乎是,您给
通知
-对象的URI错误:
“R.raw.alert”
无效


相反,如果您需要获取存储在
res/raw/
-目录中的文件的URI,请使用以下模式:
“android.resource://”+getPackageName()+“/”+R.raw。您的\u raw\u文件
,如下所述:

提高您的接受率。此外,LogCat中应该有某种错误或异常消息。将它添加到您的问题中。不,日志中没有错误是的,我检查了它,但没有发生任何事情,日志中没有显示错误您的声音是什么文件类型,您的URI是什么,您是否记录了日志Cat的URI路径,并手动检查是否可以在那里找到所需的文件?