Notification sound from URI parse does not work

android, android-notifications, uri

Solution

use

notification.sound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE
        + "://" + getPackageName() + "/raw/start");

Note one thing.

String android.content.ContextWrapper.getPackageName()

returns the package name of your android aplication. And

package com.example.memoryGuide;

shows the package name of your source package name.

Problem

There are at least 7 questions on Stackoverflow related to this, I have tried every single suggestion and solution multiple times and none of them have worked. Here is my latest attempt: ``` private Notification createNotification() { Notification notification = new Notification(); if(notifyImage=="food") { notification.icon = R.drawable.food; notification.sound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://com.example.memoryGuide/raw/start"); } else { notification.icon = R.drawable.bar; notification.sound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://com.example.memoryGuide/raw/start"); } notification.when = System.currentTimeMillis(); notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.flags |= Notification.FLAG_SHOW_LIGHTS; notification.defaults |= Notification.DEFAULT_VIBRATE; notification.defaults |= Notification.DEFAULT_LIGHTS; notification.ledARGB = Color.WHITE; notification.ledOnMS = 1500; notification.ledOffMS = 1500; return notification; } ``` You can see the two times I try and use a sound which never works, but the icons work perfectly. I do not know if I am missing anything in order to get this to work, but all of the code I am using is in my post. My sound file is in res/raw/start.mp3, I can get this sound to work when pressing a button, so the sound is fine. I think the package name is right, my application at has this at the top of each class: ``` package com.example.memoryGuide; ``` Any ideas why the sound never plays?

Original source