2017-04-22 52 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; 
}