Justin Macrae
Justin Macrae

Reputation: 53

Notification works but doesn't play the audio file (.mp3) attached to it

Hey guys so iv'e recently been trying to program a timer where once the timer hits 0 a notification appears telling the user what happened and will play a sound along with it. Ive been able to get my default phone notification sound to work but i cant seem to get this custom sound to work. Heres my code am I missing something?

Uri sound = Uri.parse("android.resource://com.example.jmac.spawny"+R.raw.fresh_overs);
    PendingIntent intent = PendingIntent.getActivity(this, 100, new Intent(this, Guardian.class), 0);

    NotificationCompat.Builder nb = new NotificationCompat.Builder(this);
    nb.setSmallIcon(R.drawable.spawnymascot);
    nb.setSound(sound);
    nb.setContentTitle("Overs Up Bro!");
    nb.setContentText("Click to return to Guardian Screen");
    nb.setContentIntent(intent);

    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    nm.notify(100, nb.build());

Upvotes: 0

Views: 80

Answers (1)

tachyonflux
tachyonflux

Reputation: 20211

You're missing a forward slash to separate your package name from the resource id:

Uri sound = Uri.parse("android.resource://com.example.jmac.spawny/"+R.raw.fresh_overs);

Upvotes: 2

Related Questions