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());
Try these steps: Go to Settings > Sound & Notification > App Notifications. Select the app, and make sure that Notifications are turned on and set to Normal. Make sure that Do Not Disturb is turned off.
If your target platform is Android, you can test a push notification on an emulator if the emulator target uses a version of Google APIs to receive the push notifications.
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 !
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With