Get thumbnail Uri/path of the image stored in sd card + android

前端 未结 8 712
自闭症患者
自闭症患者 2020-11-28 04:46

SDK version - 1.6

I am using following intent to open android\'s default gallery:

Intent intent = new Intent();
                inte         


        
8条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-28 04:56

    Based on @Karan's answer and following comments, just for the people that arrive here (like I did) and need a ready-to-work code:

    public String getThumbnailPath(Uri uri) {
        String[] projection = { MediaStore.Images.Media._ID };
        String result = null;
        Cursor cursor = managedQuery(uri, projection, null, null, null);
        int column_index = cursor
                .getColumnIndexOrThrow(MediaStore.Images.Media._ID);
    
        cursor.moveToFirst();
        long imageId = cursor.getLong(column_index);
        cursor.close();
    
        cursor = MediaStore.Images.Thumbnails.queryMiniThumbnail(
                getContentResolver(), imageId,
                MediaStore.Images.Thumbnails.MINI_KIND,
                null);
        if (cursor != null && cursor.getCount() > 0) {
            cursor.moveToFirst();
            result = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails.DATA));
            cursor.close();
        }
        return result;
    }
    

提交回复
热议问题