我有一个带照片的应用程序,然后在imageView上显示,但问题出在Android one或7.1.1 Nougat手机上没有显示屏幕上的图像,其他手机工作正常。(适用于三星S7 Edge Nougat 7.0.0以及Nexus 5X Marshmallow 6.0.0完美无缺。)注意:它不会在7.1.1上崩溃,只是在屏幕上没有显示和图像。
拍照后的代码示例:
if (requestCode == REQUEST_TAKE_PHOTO && resultCode == RESULT_OK) {
// Show the thumbnail on ImageView
Uri imageUri = Uri.parse(mCurrentPhotoPath);
File file = new File(imageUri.getPath());
try {
InputStream ims = new FileInputStream(file);
binding.ivPhoto.setImageBitmap(BitmapFactory.decodeStream(ims));
} catch (FileNotFoundException e) {
return;
}
}
答案 0 :(得分:0)
我发现了问题,问题是,当我尝试将文件保存到目录时,它无法在外部驱动器中找到目录,解决方法是,如果您没有这样的目录,则需要创建新目录。 / p>
private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String path = Environment.getExternalStorageDirectory() + "/" + "AdoptPet/";
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = new File(Environment.getExternalStoragePublicDirectory(
path), "Camera");
if (!storageDir.exists()) {
storageDir.mkdirs();
}
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
// Save a file: path for use with ACTION_VIEW intents
mCurrentPhotoPath = "file:" + image.getAbsolutePath();
return image;
}