通知有效,但不播放附加到其上的音频文件(.mp3)

时间:2015-08-19 20:55:04

标签: java android notifications

嘿伙计们,所以我最近一直试图设定一个计时器,一旦计时器点击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());

1 个答案:

答案 0 :(得分:2)

您缺少正斜杠以将您的包名称与资源ID分开:

Uri sound = Uri.parse("android.resource://com.example.jmac.spawny/"+R.raw.fresh_overs);