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?