java - parse custom push sound -
sorry english. use parse.com want create custom sound when push. when send push, phone vibrates. there no sound , message not show too.
this sound: image (i have not 15 reputation)
code:
public class mybroadcastreceiver extends parsepushbroadcastreceiver { private int notification_id = 1; @override public void onpushopen(context context, intent intent) { intent = new intent(context, mainactivity.class); i.putextras(intent.getextras()); i.setflags(intent.flag_activity_new_task); context.startactivity(i); } @override public void onreceive(context context, intent intent) { try{ string jsondata = intent.getextras().getstring("com.parse.data"); jsonobject json = new jsonobject(jsondata); string title = null; if(json.has("title")) { title = json.getstring("title"); } string message = null; if(json.has("alert")) { message = json.getstring("alert"); } if(message != null) { generatenotification(context, title, message); } } catch(exception e) { log.e("notif error", e.tostring()); } } private void generatenotification(context context, string title, string message) { intent intent = new intent(context, mainactivity.class); pendingintent contentintent = pendingintent.getactivity(context, 0, intent, 0); notificationmanager mnotifm = (notificationmanager) context.getsystemservice(context.notification_service); if(title == null) { title = context.getresources().getstring(r.string.app_name); } final notificationcompat.builder mbuilder = new notificationcompat.builder(context) //setsmallicon(r.drawable.icon) .setcontenttitle(title) .setcontenttext(message) .setstyle(new notificationcompat.bigtextstyle() .bigtext(message)) .addaction(0, "view", contentintent) .setautocancel(true) .setdefaults(new notificationcompat().default_vibrate) .setsound(uri.parse("android.resource://" + context.getpackagename() + "/beep1.mp3")); mbuilder.setcontentintent(contentintent); mnotifm.notify(notification_id, mbuilder.build()); } }
upd:
this not work too, have standart sound
@override protected notification getnotification(context context, intent intent) { notification n = super.getnotification(context, intent); n.sound = uri.parse("android.resource://" + context.getpackagename() + "beep1.mp3"); return n; }
upd:
i pu mp3 folder res/raw/beep1.mp3
, use ("android.resource://" + context.getpackagename() + r.raw.beep1);
not help
assuming have own subclass of parsepushbroadcastreceiver , declared in manifest, recommend put mp3 file in /raw
folder , change getnotification()
method follows
@override protected notification getnotification(context context, intent intent) { notification n = super.getnotification(context, intent); n.defaults = 2; n.sound = uri.parse("android.resource://" + context.getpackagename() + "/" + r.raw.beep1); return n; }
if want change sound getnotification()
method 1 need overrid
Comments
Post a Comment