admin 管理员组文章数量: 1086019
In my project i'm trying to use custom sound in notifications.
I write it like this:
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, CHANNEL_ID)
.setContentTitle(context.getString(R.string.alarm))
.setContentText(intent.getStringExtra("alarm_title"))
.setSmallIcon(R.drawable.bell_outline_symbolic)
.setSound(customSoundUri)
.setAutoCancel(true);
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
I except it to play the sound from the Uri, but it playing the default notification sound (set by the device settings). The Uri is on the sounds library of the device (for example: content://media/internal/audio/media/13?title=Tweeters&canonical=1
), and it works well with MediaPlayer, but not with notifications.
I'm want it to use the same NotificationChannel, so I'm not setting it on the channel.
What am I doing wrong?
本文标签: androidChange notification sound with setSound(Uri uri)Stack Overflow
版权声明:本文标题:android - Change notification sound with .setSound(Uri uri) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1743992866a2515054.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论