how to view image through image id in android

我只是一个虾纸丫 提交于 2019-12-06 08:09:43
int imageID = cursor.getInt( cursor.getColumnIndex(MediaStore.Images.Media._ID) ); 

Uri uri = Uri.withAppendedPath( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, Integer.toString(imageID) );

To get the Uri from id use this code.

private void getPhoneGalleryImages() {

    Cursor cursor = cr.query(
            MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null, null,
            null, null);
    cr = getActivity().getContentResolver();
    if(cursor != null)
    {
        if (cursor.moveToFirst()) {
            do {
                String id = cursor.getString(cursor
                        .getColumnIndex(MediaStore.Images.Thumbnails._ID));
                String path = cursor.getString(cursor
                        .getColumnIndex(MediaStore.Images.Media.DATA));
            } while (cursor.moveToNext());
        }
        cursor.close();
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!