0

I have a notification that works perfectly, but no sound plays, not even the default sound, I've tried numerous approaches listed on this website to try to get a sound to play but to no avail.

If I create a media player I can play the audio file just fine when the application starts up, but I can't seem to get the file to play when a notification is started.

final Notification.Builder notifyDetailsBuilder = new Notification.Builder(context)
.setContentTitle("Your Jewellery Received A New Message")
.setContentText("Click To View Message")
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.drawable.ic_launcher)
.setAutoCancel(true)                
.setContentIntent(intent);

final Notification notifyDetails = notifyDetailsBuilder.getNotification();                              
mNotificationManager.notify(35178, notifyDetails);

Any help would be greatly appreciated.

Hariharan
  • 24,741
  • 6
  • 50
  • 54
Ashley Stewart
  • 161
  • 1
  • 3
  • 12

2 Answers2

0

Try

RingtoneManager ringtoneManager = new RingtoneManager(context);
Uri defaultSoundUri = ringtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
final Notification.Builder builder = new Notification.Builder(context)
    ...
    .setSound(defaultSoundUri);
Karakuri
  • 38,365
  • 12
  • 84
  • 104
0

set the defaults to 0

RingtoneManager ringtoneManager = new RingtoneManager(context);
Uri defaultSoundUri = ringtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
final Notification.Builder builder = new Notification.Builder(context)
    .setDefaults(0)
    .setSound(defaultSoundUri)

... the rest of your code

Brian
  • 4,328
  • 13
  • 58
  • 103