I have tried many things suggested here, but nothing works for me. here is my source code:
Intent resultIntent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, resultIntent,PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("title")
.setContentText("Hello World!");
mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
mBuilder.setContentIntent(contentIntent);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, mBuilder.build());
The notification appears but no sound, any help ?
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.
Tap the Settings button in the in the top-right corner. Tap where it says Sound notifications are active. Tap the toggle switch for each sound to turn it on or off or tap on each sound to set specific sound, vibration and visual alerts.
Set the default flags:
mBuilder.setDefaults(Notification.DEFAULT_SOUND|Notification.DEFAULT_LIGHTS|Notification.DEFAULT_VIBRATE);
Use notification.sound instead of mBuilder.setSound() solved my problem.
Here is the code -
Notification notification = mBuilder.build();
notification.sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
mNotificationManager.notify(0, notification);
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