我试图覆盖通知声音并播放自己的通知声音。
当前代码是:
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_notifications_white_24dp)
.setContentTitle(text)
.setColor(context.getResources().getColor(R.color.colorAccent))
.setSound(soundUri);
// Sets an ID for the notification
int mNotificationId = 2580;
// Gets an instance of the NotificationManager service
NotificationManager mNotifyMgr =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// Builds the notification and issues it.
mNotifyMgr.notify(mNotificationId, mBuilder.build());
但是原始通知(通过声音)覆盖了我的声音。
有什么办法吗?
编辑:
当我尝试播放声音时,两个声音都在播放。有时原始声音优先,而自定义声音则首先播放。
我只想听到自定义声音。
最佳答案
创建res/raw
文件夹并将通知声音放入此文件夹
试试这个
notification.sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notifysound);
关于android - 覆盖通知声音Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38543299/