-1

I know this question has been answered before, but still, I can't make it work. I already put the mp3 into the raw folder and I know the route to it is valid because I tested with the Ringtone and MediaPlayer class. The notification is created fine but without sound (And I have the volume at max on my device). Here's my code

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)   
.setLargeIcon(icon)   
.setSmallIcon(R.drawable.logo)  
.setContentTitle(notification.getTitle())   
.setContentText(notification.getBody())   
.setSound(sound)   
.setPriority(Notification.PRIORITY_HIGH);     
mBuilder.setContentIntent(contentIntent);   
Notification mNotification = mBuilder.build();   
mNotification.sound = sound;   
NotificationManager mNotificationManager = (NotificationManager) context    
.getSystemService(Context.NOTIFICATION_SERVICE); 
mNotificationManager.notify(MESSAGE_NOTIFICATION_ID, mNotification);
neo73
  • 434
  • 5
  • 20
  • Can you please format your code properly? Like it is it's very difficult to read. You can find some help here: https://stackoverflow.com/editing-help – Kuba Nov 01 '17 at 18:38

1 Answers1

0

Try this

 notification.sound =Uri.parse("android.resource://"+context.getPackageName()+"/"+R.raw.FILE_NAME);//Here is FILE_NAME is the name of file that you want to play

(or)

MediaPlayer mp= MediaPlayer.create(contexto, R.raw.your_sound);
                mp.start();
Gowthaman M
  • 8,057
  • 8
  • 35
  • 54
  • I already did that. I tested and it sounds with the MediaPlayer class, but not in the notification – Fabrizio Gagliardi Nov 01 '17 at 19:03
  • `notification.sound =Uri.parse("android.resource://"+context.getPackageName()+"/"+R.raw.FILE_NAME);` try this..i hope this will work...if not working let me know – Gowthaman M Nov 01 '17 at 19:06