1
Uri uri = contentResolver.insert(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, audioValues);

on some devices yields:

java.lang.UnsupportedOperationException: Unknown URI: content://media/external/audio/media at android.app.ActivityThread.handleCreateService(ActivityThread.java:2887) at android.app.ActivityThread.-wrap4(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1427) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5422) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by java.lang.UnsupportedOperationException: Unknown URI: content://media/external/audio/media at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:167) at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135) at android.content.ContentProviderProxy.insert(ContentProviderNative.java:476) at android.content.ContentResolver.insert(ContentResolver.java:1231) at company.app.MainService.setupFilesForAudioRecording(MainService.java:388) at company.app.MainService.onCreate(MainService.java:239) at android.app.ActivityThread.handleCreateService(ActivityThread.java:2877) at android.app.ActivityThread.-wrap4(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1427) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5422) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

I don't understand how it is possible I would ever get this error. How can MediaStore.Audio.Media.EXTERNAL_CONTENT_URI be an unknown URI? Is this a situation where the device does not have external storage?

Developer docs say:

External storage is not always available, because the user can mount the external storage as USB storage and in some cases remove it from the device.

But that seems like a very rare case.

ericwjr
  • 200
  • 2
  • 11
  • Because your uri is not correct? – Sohail Zahid Aug 10 '16 at 04:30
  • Reading the error usually get's you somewhere. It says right there that that URI isn't correct. – Andrew Li Aug 10 '16 at 04:33
  • whats the valus of `audioValues`? – Sohail Zahid Aug 10 '16 at 04:36
  • Possible duplicate of [Insert audio album in Android MediaStore](http://stackoverflow.com/questions/22018173/insert-audio-album-in-android-mediastore) – Pavneet_Singh Aug 10 '16 at 05:44
  • 1
    The URI is correct assuming URI is referring to MediaStore.Audio.Media.EXTERNAL_CONTENT_URI...the error message is just bad. I think the issue was the file path of the DATA(path) audioValue is non-existing for some users as @PavneetSingh alluded to. Needed to create the directory if not already created. Will see if that solves...if not will open this back up – ericwjr Aug 11 '16 at 15:02
  • @AndrewLi how can the URI be incorrect when it is a constant coming from Android framework? And lose the sarcasm, you clearly didn't understand the question. – ericwjr Oct 27 '17 at 10:52
  • @SohailZahid should it matter? The error is saying MediaStore.Audio.Media.EXTERNAL_CONTENT_URI is an unknown URI when it is a constant from [Android framework](https://developer.android.com/reference/android/provider/MediaStore.Audio.Media.html#EXTERNAL_CONTENT_URI) – ericwjr Oct 27 '17 at 11:11

1 Answers1

1

This exception is related with the path of either resource or directory.Follow the link to see the code example.

Edit : It could be possible that some device does not have external storage so you should add couple of checks before executing any storage operation.

// call this function , if true , go ahead ,storage available
public boolean isExternalStorageWritable() {
    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state)) {
        return true;
    }
    return false;
}
Pavneet_Singh
  • 36,884
  • 5
  • 53
  • 68
  • That link is a different error message...not related. – ericwjr Oct 27 '17 at 11:07
  • @ericwjr you can use [Checking media availability](https://developer.android.com/guide/topics/data/data-storage.html#filesExternal) to confirm the existence of external storage and not all devices – Pavneet_Singh Oct 27 '17 at 13:06