2017-04-22 55 views
0

我有一个应用程序,需要照片然后显示在imageView上,但问题是在Android的一个或7.1.1牛轧糖手机不显示屏幕上的图像,其他手机工作完美(它可以在三星S7边缘牛轧糖7.0.0和Nexus 5X棉花糖6.0.0完美。)注意:它不是在7.1.1崩溃,只是没有显示并在屏幕上显示图像。在拍照后ImageView.setImageBitmap(bla)功能不适用于Android One Nougat 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

我发现这个问题,问题是,当我试图文件保存到目录它无法找到外部驱动器的目录,解决的办法是,如果你没有这样的目录,你需要创建一个新目录。

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; 
}