Reputation: 359
I am going nuts with a problem with notifications
on Android: While I was developing my project, suddenly the emulator plays no notification sounds anymore for API
26 and higher,
e.g. the API which require a channel.
Of course I have set up a channel and it has worked great before! I have reinstalled the app, deleted the channel, even set up another AVD with a API
27, same result: no sound ! (the notification does pop up)
Obviously I have checked that notification sounds are enabled, also for this specific channel, all seems OK, just no sounds. If I play a test using:
RingtoneManager.getRingtone(context, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)).play();
it works as it should, so no hardware problem.
On lower APIs
pre 26 where you don't need a channel, the sound does play.
Anybody had the same problem?
//make the channel
//The Config class is imported and the constants resolved, not the problem
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
NotificationChannel channel = new NotificationChannel(
Config.CHANNEL_1_ID,
Config.CHANNEL_1_NAME,
NotificationManager.IMPORTANCE_HIGH);
channel.setDescription(Config.CHANNEL_1_DESC);
channel.enableLights(true);
channel.enableVibration(true);
channel.setShowBadge(true);
NotificationManager manager = getSystemService(NotificationManager.class);
manager.createNotificationChannel(channel);
}
// send notification
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context, Config.CHANNEL_1_ID)
.setSmallIcon(R.drawable.ic_notifications_black_24dp)
.setContentTitle(title)
.setContentText(body)
.setAutoCancel(false)
.setColor(context.getResources().getColor(R.color.colorPrimary))
.setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND | Notification.FLAG_SHOW_LIGHTS)
.setPriority(NotificationCompat.PRIORITY_HIGH);
NotificationManagerCompat mNotificationMgr = NotificationManagerCompat.from(context);
mNotificationMgr.notify(1, mBuilder.build());
Upvotes: 10
Views: 5311
Reputation: 31
You may need to check Tools->SDK Manager->Appearance & Bahaviour->Notifications "Play sound" checkbox for the "Android emulator" and "Android" to get notifications sounds (i.e. when other sounds work, but there's not notification sound).
Upvotes: 3
Reputation: 171
On Pie 9.0 (api 28), you need to complete setup process. After doing it, the sound of notification channels will run well. It is same for both Emulator and physical devices. If you have not done it, all notification on device will be run on silent, regardless of importance level.
Upvotes: 5
Reputation: 126
For me the problem was the ring volume on the emulator. Apparently it was on zero by default and there was no indication for it on the top bar. Also when pressing the volume keys it would open the media volume and not the ring volume! I had to increase the ring volume via android settings -> sound.
Upvotes: 0
Reputation: 359
Seems I found the answer: I had to go through the "Finish setting up your Android SDK" wizard on the emulator. Clicked "skip" for everything, now it seems to work again. Weirdly enough, I didn't do that initially and still the notifications worked as expected... duh !
Upvotes: 19