最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

android - Change notification sound with .setSound(Uri uri) - Stack Overflow

programmeradmin1浏览0评论

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?

发布评论

评论列表(0)

  1. 暂无评论