[英]Android Notification custom sound not working
我已經在網上搜索並找到了一些與在android通知中設置聲音相關的帖子,並按照它們進行了操作,但以我為例,我在android通知中獲得了默認通知聲音。 這是我的代碼:
builder.setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notification_message));
我也關注了這篇文章,但是沒有運氣。
供您參考:我已經使用MediaPlayer播放了URI,然后運行正常。
我的部分代碼:
NotificationCompat.Builder builder = new NotificationCompat.Builder(appContext);
builder.setContentTitle(message.notificationTitle);
builder.setContentText(message.notificationSubtitle);
builder.setTicker(message.notificationTitle);
builder.setSmallIcon(R.drawable.ic_action_inbox);
Uri uri = Uri.parse("android.resource://" + appContext.getPackageName() + "/" + R.raw.notification_message);
builder.setSound(uri);
builder.setVibrate(new long[]{1000, 1000, 1000});
builder.build();
誰能解釋什么問題。 怎么做? 我被卡住了:(
使用Context.getPackageName()方法獲取Application的程序包名稱。
Uri.parse("android.resource://" + context.getPackageName() + "/" + R.raw.notification_message)
去掉
Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notification_message)
抱歉 是我的錯 我使用以下行:
builder.setDefaults(Notification.DEFAULT_ALL);
造成了問題。 評論此行將其修復。
感謝您的回答:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.