开发者

Android getting image ID chosen from SDCard and set it to ImageView

So, basically, I'm trying to change an ImageView from images in SDCARD.

Here's some code from me :

String[] images = {MediaStore.Images.Thumbnails._ID};
                Cursor cc = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                        images,
                        null,
                        null,
                        MediaStore.Images.Thumbnails.IMAGE_ID);  
                startManagingCursor(cc);  
                photo.setImageURI(Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, <ima开发者_运维技巧ge ID>));

What's confusing me is how to retrieve the image ID... as you can see, Uri.withAppendedPath() requires an image ID...

I'd appreciate it if someone can give a sample code for me..

THX


This helps ?

    String[] images = {MediaStore.Images.Thumbnails._ID};
    Cursor cc = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                    images,
                    null,
                    null,
                    MediaStore.Images.Thumbnails.IMAGE_ID);  

    if (!cc.moveToFirst())
        return null;

    String imgId = imgCursor.getString(cc
            .getColumnIndex(BaseColumns._ID));

    Uri uri = Uri.withAppendedPath(
            MediaStore.Images.Media.EXTERNAL_CONTENT_URI, imgId);
    photo.setImageURI(uri);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜