I want to display album art with album name in listview. But i am not getting the way to display album art. I have tried from cover art on android.
Here is my Code :
Cursor cursor = managedQuery(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, null, null, null, null);
if (cursor == null)
{
//Query Failed , Handle error.
}
else if (!cursor.moveToFirst())
{
//No media on the device.
}
else
{
int titleColumn = cursor.getColumnIndex(android.provider.MediaStore.Audio.Albums.ALBUM_ART);
int id = cursor.getColumnIndex(android.provider.MediaStore.Audio.Albums.ALBUM_ID); //here value i m getting -1 .
for(int i=0;i<cursor.getCount();i++)
{
if(id<0)
{
Long album =Long.parseLong(cursor.getString(id));
String coverPath = cursor.getString(titleColumn);
Context context = null;
ContentResolver res = context.getContentResolver();
Uri uri = ContentUris.withAppendedId(sArtworkUri, album);
if (uri != null)
{
InputStream in = null;
try
{
in = res.openInputStream(uri);
Bitmap b = BitmapFactory.decodeStream(in, null, sBitmapOptions);
ImageView coverAlbum=(ImageView)findViewById(R.id.thumbnail);
coverAlbum.setImageBitmap(b);
} catch (FileNotFoundException ex)
{
}
}
}
//code to insert in listview
cursor.moveToNext();
}
}
cursor.close();
}
But i am getting the album_id -1. So i am not getting album_id for album but i am having album song in my sdcard. And sdcard is having folder like albumthums which includes some files. So please give me solution to get album name and art. Thanx in Advance.
This is my error log :
12-03 15:19:22.051: WARN/System.err(32334): java.lang.NullPointerException
12-03 15:19:22.060: WARN/System.err(32334): at com.mnp.AlbumList.onCreate(AlbumList.java:59)
12-03 15:19:22.120: WARN/System.err(32334): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-03 15:19:22.130: WARN/System.err(32334): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
12-03 15:19:22.140: WARN/System.err(32334): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
12-03 15:19:22.161: WARN/System.err(32334): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
12-03 15:19:22.171: WARN/System.err(32334): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
12-03 15:19:22.180: WARN/System.err(32334): at android.os.Handler.dispatchMessage(Handler.java:99)
12-03 15:19:22.201: WARN/System.err(32334): at android.os.Looper.loop(Looper.java:123)
12-03 15:19:22.210: WARN/System.err(32334): at android.app.ActivityThread.main(ActivityThread.java:4363)
12-03 15:19:22.220: WARN/System.err(32334): at java.lang.reflect.Method.invokeNative(Native Method)
12-03 15:19:22.240: WARN/System.err(32334): at java.lang.reflect.Method.invoke(Method.java:521)
12-03 15:19:22.250: WARN/System.err(32334): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
12-03 15:19:22.260: WARN/System.err(32334): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
12-03 15:19:22.270: WARN/System.err(32334): at dalvik.system.NativeStart.main(Native Method)