i am trying to set custom ring when notification come from firebase, notification is working fine in all devices but when i set custom ringtone it not work in OREO 8 .
i already applied many answer from stackoverflow. like "this" but not work for me.
please check the my method code , if write wrong any thing then please read
thanks in advance
void SendNotification(String title,String msg){
Uri soundUri = Uri.parse("android.resource://" + getApplicationContext().getPackageName() + "/raw/message_tone");
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this,channelId);
mBuilder.setSmallIcon(R.mipmap.ic_launcher);
mBuilder.setContentTitle(title);
mBuilder.setContentText(msg);
mBuilder.setSound(soundUri);
mBuilder.setAutoCancel(true);
Intent resultIntent = new Intent(this, MainActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
//If Version OREO Then Get Channel
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel mChannel;
String channelId = "channel-01";
String channelName = "Firebase";
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
// Creating an Audio Attribute
AudioAttributes audioAttributes = new AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
.build();
mChannel = new NotificationChannel(channelId, channelName, importance);
mChannel.setSound(soundUri,audioAttributes);
mNotificationManager.createNotificationChannel( mChannel );
mBuilder.setChannelId(channelId);
}
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
// notificationID allows you to update the notification later on.
mNotificationManager.notify(0, mBuilder.build());
}