Friday, 15 June 2012

java - Android: Custom notification sound not playing -



java - Android: Custom notification sound not playing -

i've tried pretty much available answers on site, somehow cannot notification sound work. current code i'm testing (the notification built in alarm reciever):

public class alarmreceiver extends broadcastreceiver { private static final int notification_id = 0; @override public void onreceive(context context, intent intent) { notificationcompat.builder builder = new notificationcompat.builder(context) .setcontenttitle(context.getstring(r.string.app_name)) .setcontentintent(pendingintent.getactivity(context, 0, new intent(context, mainactivity_.class), 0)) .setcontenttext("temporary text") .setautocancel(true) .setsound(uri.parse(contentresolver.scheme_android_resource + "://" + context.getpackagename() + "/raw/alert")) .setdefaults(notification.default_lights | notification.default_vibrate) .setpriority(notificationcompat.priority_default) .setwhen(system.currenttimemillis()) .setsmallicon(r.drawable.ic_stat_notification); notification notification = builder.build(); notificationmanager notificationmanager = (notificationmanager) context.getsystemservice(context.notification_service); notificationmanager.notify(notification_id, notification);

the sound however, can played via mediaplayer, format not issue here. have lenght of sound (30 seconds)? give thanks help!

try changing .setsound() this

.setsound(uri.parse("android.resource://" + context.getpackagename() + "/" + r.raw.alert))

hope work

java android audio notifications

No comments:

Post a Comment