2

I've searched the web and found some post related to setting sound on android notification and followed them but in my case I am getting default notification sound on android notification. Here's my code:

builder.setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notification_message));

I've also followed this post, but no luck.

For your information: I've played the URI using MediaPlayer and it's working fine then.

Part of my code:

NotificationCompat.Builder builder = new NotificationCompat.Builder(appContext);
builder.setContentTitle(message.notificationTitle);
builder.setContentText(message.notificationSubtitle);
builder.setTicker(message.notificationTitle);
builder.setSmallIcon(R.drawable.ic_action_inbox);
Uri uri = Uri.parse("android.resource://" + appContext.getPackageName() + "/" + R.raw.notification_message);
builder.setSound(uri);
builder.setVibrate(new long[]{1000, 1000, 1000});
builder.build();

Can anyone explain what's the issue. How to do it? I'm stuck :(

Community
  • 1
  • 1
Mostafa Imran
  • 659
  • 2
  • 9
  • 28

2 Answers2

1

Sorry folks. It was my mistake. I used following line:

builder.setDefaults(Notification.DEFAULT_ALL);

which created the problem. commenting the line fixed it.

Thanks for your answers :)

Mostafa Imran
  • 659
  • 2
  • 9
  • 28
0

Use Context.getPackageName() method to get the package name of Application.

 Uri.parse("android.resource://" + context.getPackageName() + "/" + R.raw.notification_message)

remove

Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notification_message)
sasikumar
  • 12,540
  • 3
  • 28
  • 48