Reputation: 139
So, my code was working perfectly 1 month ago. But now my custom sound does not play at all.
My device : Mi note 4
Android version 7.0 NRD90M
I have spent entire day searching on the internet but could not find any working solution. Is there any update regarding my issue ?
Payload
{body={"notification_type":"","booking_id":"","booking_no_text":"","guest_mobile":"","ride_date":"","guest_name":"","pickup_longitude":"","reporting_time":"","fyear":"","pickup_latitude":"","pickup_address":""}, icon=, sound=, title=Booking Notification}
Notification builder
final Intent service = new Intent(this, MessagingService.class);
service.putExtra("msg", "New Trip Request");
startService(service);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(title)
.setContentText(msg_content)
.setAutoCancel(true)
.setSound(sound)
.setVibrate(new long[]{500, 0000, 0000, 500, 000});
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mBuilder.setSmallIcon(R.drawable.ic_launcher);
mBuilder.setColor(ContextCompat.getColor(mContext,R.color.colorPrimary));
} else {
mBuilder.setSmallIcon(R.drawable.ic_launcher);
}
NotificationManager mnNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String channelId = mContext.getString(R.string.default_notification_channel_id);
NotificationChannel channel = new NotificationChannel(channelId, title, NotificationManager.IMPORTANCE_DEFAULT);
mnNotificationManager.createNotificationChannel(channel);
mBuilder.setChannelId(channelId);
}
mnNotificationManager.notify(0, mBuilder.build());
stopService(service);
Earlier the sound was playing perfectly. But suddenly it stopped working.
Upvotes: 1
Views: 1523
Reputation: 139
I found the solution after 2 days of frustration. If you are using MI phone and have recently updated your UI. Then all you have to do is enable sound of your app in settings
Goto : Settings > Notifications & Status Bar > App Notifications > Select App and Enable Sound.
Reference link : https://www.reddit.com/r/Xiaomi/comments/906p09/notification_sounds_not_working_on_miui_10_8719/
Upvotes: 2