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

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -