Android notification, vibrates but no sound -
i've read of other posts on subject , think code should sounding alarm, it's not. vibrate, no sound. suggestions on how convey sound ?
another part of program able play ringtone problem seems specific routine.
this in class extends service
@override public int onstartcommand(intent intent, int flags, int startid) { uri sound = ringtonemanager.getdefaulturi(ringtonemanager.type_notification); if (sound == null) { log.i("receiver", "sound null"); } notificationmanager mynm = (notificationmanager)getsystemservice(notification_service); intent intentmain = new intent(this.getapplicationcontext(), mainactivity.class); pendingintent pintent = pendingintent.getactivity(this, 0, intentmain, 0); long[] pattern = {500,500,500,500,500,500,500,500,500}; notification mynote = new notification.builder(this) .setcontenttitle("notificationdemo") .setcontenttext("notificatindemo") .setsmallicon(r.drawable.ic_launcher) .setsound(sound) .setvibrate(pattern) .setcontentintent(pintent) .build(); mynm.notify(1, mynote); return super.onstartcommand(intent, flags, startid); }
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, , usage of audio attributes.
Comments
Post a Comment