我将图像存储在/storage/emulated/0/Download/20151010_211903.jpg
,我在代码上指定了文件名,以便可以在图库中打开它 但是当我触发它时,它只会打开我拍摄的最新照片(“相机”文件夹中的照片),而不是下载文件夹。
下面是代码
File file = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),"20151010_211903.jpg");
if (fileExt.equals("jpg") || fileExt.equals("jpeg") || fileExt.equals("JPG") || fileExt.equals("JPEG")) {
// intent.setDataAndType(Uri.fromFile(file), "image/jpeg");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Log.e("download","image come"+file.getAbsolutePath());
//log says /storage/emulated/0/Download/20151010_211903.jpg
//which is correct.
intent.setType("image/*");
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);
} else {
// intentt.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
}
}