[英]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.