GB11
GB11

Reputation: 290

Notification does not play sound in Android

I have a notification in Android that works well but it does not play the sound i specified to it:

notification.sound = Uri.parse("android.resource://com.example.code/raw/sound");

I know i am not maybe the first one who had this problem but all the posts i browsed about this did not help me.

Thank you.

Upvotes: 2

Views: 779

Answers (2)

Jorgesys
Jorgesys

Reputation: 126455

Notification.Builder mBuilder = new Notification.Builder(this)
mBuilder.setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.sound)); 

be sure to have your sound.mp3 file inside your /res/raw/ folder.

Upvotes: 1

Rodrigo Borges
Rodrigo Borges

Reputation: 474

Is any sound playing?

Make sure to not set DEFAULT_SOUND on notification.defaults or the default sound will override your custom sound.

Besides, try to use another Uri format like:

notification.sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.sound );

Upvotes: 1

Related Questions