Android
1.获得系统相册默认路径
Toast.makeText(this, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath()+"", Toast.LENGTH_SHORT).show();
2.获取媒体库图片资源,设置到Imageview
//获得所有图片
allPicPath = new ArrayList<>();
allPicPath.clear();
/**
* 需要从数据库中获取的信息:
* BUCKET_DISPLAY_NAME 文件夹名称
* DATA 文件路径
*/
String[] projection = new String[]{
MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
MediaStore.Images.Media.DATA};
/**
* 通过ContentResolver 从媒体数据库中读取图片信息
*/
Cursor cursor = getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, //限制类型为图片
projection,
MediaStore.Images.Media.MIME_TYPE + "=? or " + MediaStore.Images.Media.MIME_TYPE + "=? or " + MediaStore.Images.Media.MIME_TYPE + "=?",
new String[]{"image/jpeg","image/jpg", "image/png"}, // 这里筛选了jpg和png格式的图片
MediaStore.Images.Media.DATE_ADDED); // 排序方式:按添加时间排序
while (cursor.moveToNext()) {
//获取图片路径
String path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));
allPicPath.add(path);
}
cursor.close();
//把获得的图片显示到imageview
Bitmap bitmap = BitmapFactory.decodeFile(allPicPath.get(1)+"");
album.setImageBitmap(bitmap);