繁体   English   中英

Android Notification自定义声音不起作用

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM