From 66eb5899574cda2aae905248a58a2bd675247109 Mon Sep 17 00:00:00 2001 From: Jan Bjernler Date: Mon, 30 Apr 2012 09:16:52 +0200 Subject: [PATCH] MediaStore.Audio.Media.getContentUriForPath() returns unexpected content MediaStore.Audio.getContentUriForPath() returns an uri to internal storage if anything but /mnt/sdcard/ is sent in. This fix checks if there is an additional sdcard (normally called ext_card) or usb mass storage attached to the device and then returns an uri to the external db. The extra sdcard name and the usb mass storage name info is read from the system environment variable SECONDARY_STORAGE so if a customer chooses to change the name this will work as expected. Change-Id: Ib78bca929fe382d4770df895149a0132f0e56994 --- core/java/android/provider/MediaStore.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/core/java/android/provider/MediaStore.java b/core/java/android/provider/MediaStore.java index 0e7ab525bc910..cb6300f691f4f 100644 --- a/core/java/android/provider/MediaStore.java +++ b/core/java/android/provider/MediaStore.java @@ -1324,6 +1324,18 @@ public final class MediaStore { } public static final class Media implements AudioColumns { + + private static final String[] EXTERNAL_PATHS; + + static { + String secondary_storage = System.getenv("SECONDARY_STORAGE"); + if (secondary_storage != null) { + EXTERNAL_PATHS = secondary_storage.split(":"); + } else { + EXTERNAL_PATHS = new String[0]; + } + } + /** * Get the content:// style URI for the audio media table on the * given volume. @@ -1337,6 +1349,12 @@ public final class MediaStore { } public static Uri getContentUriForPath(String path) { + for (String ep : EXTERNAL_PATHS) { + if (path.startsWith(ep)) { + return EXTERNAL_CONTENT_URI; + } + } + return (path.startsWith(Environment.getExternalStorageDirectory().getPath()) ? EXTERNAL_CONTENT_URI : INTERNAL_CONTENT_URI); }