2016-11-10 81 views
0

我有表演一個圖像此方法從我的SD卡到Android演播室:Android的工作室 - 無法解碼流(拒絕)

public void showImage(){ 
    File imgFile = new File(Environment.getExternalStorageDirectory().getPath()+PATH+"Foto.jpg"); 
    if(imgFile.exists()){ 
     Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath()); 
     ivProfileImage.setImageBitmap(myBitmap); 
     Log.i("Image","The image exists!"); 
    } 
} 

凡ivProfileImage是ImageView的,和路徑是正確的。我得到這個消息:

E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: /storage/2673-1D16/ProfilePhotos/Foto.jpg: open failed: EACCES (Permission denied) 
I/Image: The image exists! 

而且我AndroidManifest.xml中具有的權限:

  • 「android.permission.READ_EXTERNAL_STORAGE」
  • 「android.permission.WRITE_EXTERNAL_STORAGE」

我一直在尋找答案,但沒有人爲我工作。任何想法?

在此先感謝。

+0

https://stackoverflow.com/questions/32635704/android-permission-doesnt-work-even-if-i-have-declared-it另外請注意,您的代碼適用於外部存儲,不可移動存儲。 – CommonsWare

+0

謝謝我觀察它並修復了添加權限。 –

回答

3

您必須檢查運行時權限。這是Android 6中的新功能。Look here.

+0

它爲我工作。非常感謝! –