How to add custom notification sound in Android -
this question has answer here:
i have manage notification , need manage custom sound when comes. have idea how can this?
i copied sound file raw folder, have ideas how can implement project.
thanks in advance.
firstly make folder in resource (res) name raw , put file (your_sound_file.mp3) in , use below lines of code custom sound
notificationmanager notificationmanager = (notificationmanager) context .getsystemservice(context.notification_service); notification notification = new notification(icon, message, when); string title = context.getstring(r.string.app_name); intent notificationintent = new intent(context, slidingmenuactivity.class); notificationintent.putextra("isinbox", true); // set intent not start new activity notificationintent.setflags(intent.flag_activity_clear_top | intent.flag_activity_single_top); pendingintent intent = pendingintent.getactivity(context, 0, notificationintent, 0); notification.setlatesteventinfo(context, title, message, intent); notification.flags |= notification.flag_auto_cancel;
use these lines of code custom sound
notification.sound =uri.parse("android.resource://"+context.getpackagename()+"/"+r.raw.file_name);//here file_name name of file want play // vibrate if vibrate enabled notification.defaults |= notification.default_vibrate; notificationmanager.notify(0, notification);
Comments
Post a Comment