[英]Notification works but doesn't play the audio file (.mp3) attached to it
嗨,大家好,我最近一直在尝试对计时器进行编程,一旦计时器达到0,就会出现一条通知,告诉用户发生了什么事,并随之播放声音。 我已经能够使我的默认电话通知声音正常工作,但是我似乎无法使这种自定义声音正常工作。 这是我的代码,我缺少什么吗?
Uri sound = Uri.parse("android.resource://com.example.jmac.spawny"+R.raw.fresh_overs);
PendingIntent intent = PendingIntent.getActivity(this, 100, new Intent(this, Guardian.class), 0);
NotificationCompat.Builder nb = new NotificationCompat.Builder(this);
nb.setSmallIcon(R.drawable.spawnymascot);
nb.setSound(sound);
nb.setContentTitle("Overs Up Bro!");
nb.setContentText("Click to return to Guardian Screen");
nb.setContentIntent(intent);
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.notify(100, nb.build());
您没有使用斜杠将包名称与资源ID分开:
Uri sound = Uri.parse("android.resource://com.example.jmac.spawny/"+R.raw.fresh_overs);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.