Set Notification Sound As Default Alarm Ringtone
What I've discovered is, that if I set notification sound as devices default alarm ringtone like this: val alarmTone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM) val
Solution 1:
After 8.0 Oreo You may have created the channel for play notification sound.
private static void initChannels(NotificationManager notificationManager) {
if (Build.VERSION.SDK_INT < 26) {
return;
}
NotificationChannel channel = new NotificationChannel("ID",
"NAME",
NotificationManager.IMPORTANCE_LOW);
channel.setDescription("DESC");
channel.enableVibration(false);
AudioAttributes audioAttributes = new AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
.build();
channel.setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notification), audioAttributes);
notificationManager.createNotificationChannel(channel);
}
Make sure you are using targetSdkVersion 26 or above
Post a Comment for "Set Notification Sound As Default Alarm Ringtone"