通知有效但不播放附加到它的音频文件 (.mp3)
Notification works but doesn't play the audio file (.mp3) attached to it
大家好,我最近一直在尝试编写一个计时器,一旦计时器达到 0,就会出现一条通知,告诉用户发生了什么,并会随之播放声音。我能够让我的默认 phone 通知声音正常工作,但我似乎无法让这个自定义声音正常工作。这是我的代码,我遗漏了什么吗?
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);
大家好,我最近一直在尝试编写一个计时器,一旦计时器达到 0,就会出现一条通知,告诉用户发生了什么,并会随之播放声音。我能够让我的默认 phone 通知声音正常工作,但我似乎无法让这个自定义声音正常工作。这是我的代码,我遗漏了什么吗?
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);