contentprovider之读取图片

//获取到contentprovider 次代码是用来读取 图片的也可以读取SD卡中的图片只需要更改 INTERNAL_CONTENT_URI这句话
 cursor = getContentResolver().query(MediaStore.Images.Media.INTERNAL_CONTENT_URI,
                null, null, null, null);
        while (cursor.moveToNext()){
            //获取图片的名称    cursor.getColumnIndex(MediaStore.Images.Media.DISPLAY_NAME  常量  查下
            // 可以 查询图片的名称  的列名
            String name=cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DISPLAY_NAME));
            String desc=cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DESCRIPTION));
            String size=cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.SIZE));
            //读取图片的数据
            byte[] data=cursor.getBlob(cursor.getColumnIndex(MediaStore.Images.Media.DATA));
            names.add(name);
            descs.add(size);
            String filePath=new String(data,0,data.length-1);
            filePaths.add(filePath);
        }
        for (int i = 0; i             HashMap listItems=new HashMap<>();
            listItems.put("name",names.get(i));
            listItems.put("desc",filePaths.get(i));
            Log.d("MainActivity",names.get(i));
            Log.d("MainActivity",filePaths.get(i));
            list.add(listItems);
        }
        simpleAdapter.notifyDataSetChanged();
    }

你可能感兴趣的:(contentprovider之读取图片)