Android Notification, Vibrates But No Sound
I've read some of the other posts on this subject and I think my code should be sounding an alarm, but it's not. It does vibrate, but no sound. Any suggestions on how to get this
Solution 1:
Try this:
Notification.Builder mBuilder = new Notification.Builder(this)
.setContentTitle("NotificationDemo")
.setContentText("NotificatinDemo")
.setSmallIcon(R.drawable.ic_launcher)
.setVibrate(pattern)
.setContentIntent(pIntent);
Notification myNote = mBuilder.build();
if(Build.VERSION.SDK_INT >= 21) {
myNote.sound = sound;
myNote.category = Notification.CATEGORY_ALARM;
AudioAttributes.Builder attrs = new AudioAttributes.Builder();
attrs.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION);
attrs.setUsage(AudioAttributes.USAGE_ALARM);
myNote.audioAttributes = attrs.build();
} else {
mBuilder.setSound(sound, AudioManager.STREAM_ALARM);
myNote = mBuilder.build();
}
myNM.notify(1, myNote);
Also check these: Lollipop notification feature, AudioAttributes
class used in new notification system, and usage of Audio Attributes.
Solution 2:
First Check your device notification sound settings.
Then try this
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle(getString(R.string.app_name))
.setContentText(someText)
.setDefaults(Notification.DEFAULT_SOUND)
.setAutoCancel(true);
Solution 3:
Try this code
Notification myNote = new Notification.Builder(this)
.setContentTitle("NotificationDemo")
.setContentText("NotificatinDemo")
.setSmallIcon(R.drawable.ic_launcher)
.setSound(Notification.DEFAULT_SOUND)
.setVibrate(pattern)
.setContentIntent(pIntent)
.build();
Post a Comment for "Android Notification, Vibrates But No Sound"