I'm working with notification channels and as standard I want to enable sound for notification. I set sound in NotificationChannel options, but it's disabled. I also tried to set Audio in the NotificationCompat.Builder but this either didn't worked.
Ps: I don't know if my phone is the problem, I have an Redmi Note 7 with Android 9 and MIUI.
I've tried in the Channel options, NotificationCompat.Builder, both and each once solo, but it didn't worked. But if I turn the option in the Channel settings on it works but I don't want that the user needs to do that.
String CHANNEL_ID = "coin_master_item_generator";
CharSequence CHANNEL_NAME = "Item Generator Coin Master";
AudioAttributes audioAttributes = new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
.build();
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);
channel.setDescription("Notifies when Items are generated");
channel.enableVibration(true);
channel.setVibrationPattern(new long[]{2000,1000});
channel.enableLights(true);
channel.setLightColor(Color.WHITE);
channel.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION),audioAttributes);
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.createNotificationChannel(channel);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_launcher_foreground)
.setContentTitle("Item Generator")
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setContentText("New Items generated");
notificationManager.notify(1524,builder.build());