I’ve noticed something odd about the behavior of my code and am hoping someone can shed some light.
String temp = "file:///sdcard/music/05 Folsom Prison Blues.mp3";
String temp2 = "content://media/external/audio/media/10";
Uri uri = Uri.parse(temp);
Cursor musiccursor = null;
musiccursor = managedQuery(uri, null, null, null, null);
try {
if (musiccursor.moveToFirst()) {
String title;
int titleColumn = musiccursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE);
title = musiccursor.getString(titleColumn);
item.setText(title);
}
The problem I’m noticing is that with temp2 everything runs fine, I’m able to get the song’s title. But with temp musiccursor is null every time so we throw a nullpointerexception. Any idea what the difference is here? I’ve tried the encoded version of temp (converts spaces to %20 etc) and that doesn’t work. I can use the uri that is created with temp2 to play the song using an intent no problem… Not sure what I’m missing here.
Thanks in advance!
file://is not a scheme managed by a content provider (onlycontent://is), and so aContentResolverwill not be able to do anything with it.