Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't find a consistent method of loading media files from Android SD card
    primarykey
    data
    text
    <p>I'm getting inconsistent results between my tablet and my AVD emulated devices when trying to load music from the SD card. The method that works on my tablet doesn't work on the virtual devices and vice versa.</p> <p>Here is the code that works on my tablet. It is the better approach and allows me to access all of the details on the file including artist, album, album art, etc... (My tablet is running jelly bean.)</p> <pre><code>Uri uri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; Cursor cur = mContentResolver.query(uri, null, MediaStore.Audio.Media.IS_MUSIC + " = 1", null, null); cur.moveToFirst(); { do { HashMap&lt;String, Object&gt; song = new HashMap&lt;String, Object&gt;(); song.put("songTitle", cur.getString(titleColumn)); Uri path = ContentUris.withAppendedId(uri,cur.getLong(idColumn)); String songPath = path.toString(); song.put("songPath", songPath); song.put("artistName",cur.getString(artistColumn)); song.put("albumName",cur.getString(albumColumn)); song.put("albumId", cur.getInt(albumIdColumn)); song.put("songId", cur.getInt(idColumn)); songsList.add(song); } while (cur.moveToNext()); } </code></pre> <p>But on the emulated device the cursor is empty so no songs are ever added to the list. I have pushed songs onto the emulator's sd card, but no luck. The following code does find the songs on the virtual device but only provides the song name and file path, no artist or album information. (The virtual device is Android 4.2 and API level 17)</p> <pre><code>final String MEDIA_PATH = new String("/sdcard/"); File home = new File(MEDIA_PATH); if (home.listFiles(new FileExtensionFilter()).length &gt; 0) { for (File file : home.listFiles(new FileExtensionFilter())) { HashMap&lt;String, Object&gt; song = new HashMap&lt;String, Object&gt;(); song.put("songTitle", file.getName().substring(0, (file.getName().length() - 4))); song.put("songPath", file.getPath()); songsList.add(song); } } </code></pre> <p>However, the File (home) is empty when this code is run on my tablet and it returns no data. My solution at this point is to run both ways in order to populate the song list. However, for any devices that have to use the 2nd method I won't have artist or album info. Am I missing something here, maybe an anomaly related to a virtual device, or is this just the frustration of dealing with so many different devices?</p> <p>Many Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload