so i've been having this issue for quite sometime now. My notification is not making any sound at all, I've tried changing it into the default sound programmatically and it's not working. I'm currently using the Android Emulator in Android Studio (Pixel 2XL Oreo). Below is the code, I've initiated the channel and set the sound in the channel, and it's not working.
// Get the uri of the sound
Uri sound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE
+ "://" + mContext.getPackageName() + "/" + R.raw.kepingalertupsound);
// Get the Notification Manager using System Service for creating notification
NotificationManager notificationManager = (NotificationManager)
mContext.getSystemService(Context.NOTIFICATION_SERVICE);
// Create a notification channel to initiate notification
// Use High importance to pop-up display
// Check SDK version
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// Creating Audio Attribute
AudioAttributes attributes = new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
.build();
NotificationChannel mChannel = new NotificationChannel(
KEPING_NOTIFICATION_CHANNEL_ID,
mContext.getString(R.string.alert_notification_channel_name),
NotificationManager.IMPORTANCE_HIGH);
// Configure the notification channel
mChannel.setDescription(notificationResult);
mChannel.enableLights(true);
mChannel.enableVibration(true);
mChannel.setSound(sound, attributes);
if(notificationManager != null) {
notificationManager.createNotificationChannel(mChannel);
}
}
// Build the notification here
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(mContext, KEPING_NOTIFICATION_CHANNEL_ID)
.setColor(ContextCompat.getColor(mContext, R.color.colorPrimaryDark))
.setSmallIcon(R.drawable.ic_bitcoin_color)
.setLargeIcon(largeIcon(mContext))
.setContentTitle(mContext.getString(R.string.notification_alert_title))
.setContentText(notificationResult)
.setContentIntent(contentIntent(mContext))
.setDefaults(Notification.DEFAULT_SOUND)
.setAutoCancel(true);
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
notificationBuilder.setPriority(NotificationCompat.PRIORITY_HIGH);
} else {
notificationBuilder.setChannelId(KEPING_NOTIFICATION_CHANNEL_ID);
}
if(notificationManager != null) {
// Start the notification
notificationManager.notify(ALERT_NOTIFICATION_ID, notificationBuilder.build());
}
// Unregister Content Observer
mContext.getContentResolver().unregisterContentObserver(mContentObserver);