file.canWrite() says “true” but I can't write on removable storage (kit kat)

核能气质少年 提交于 2019-12-10 16:36:39

问题


I recieve a intent from camera with a photo taken in this path:
/storage/extSdCard/DCIM/Camera/photoCaptured.jpg

And I want to resize (already does) of the image and overwrite in the same path...
I can do it on 2.3, 4.1 and 4.3, but... not in 4.4

so... maybe the problem is the permission on this folder, so I check with this...

if( myFile.canWrite() ){
    Log.e("myMethodToSave", "you have permission: " + myFile);
} else {
    Log.e("myMethodToSave", "forget it!: " + myFile);
}  

...and I have permission to write but 4.4, says Permission Denied
Why?
How can I resolve this?

EDITED

salida = new FileOutputStream(myFile);  //error only on kit kat
bitmap.compress(Bitmap.CompressFormat.JPEG, 70, salida); 

回答1:


The reason from http://source.android.com/devices/tech/storage/index.html

The WRITE_EXTERNAL_STORAGE permission must only grant write access to the primary external storage on a device. Apps must not be allowed to write to secondary external storage devices, except in their package-specific directories as allowed by synthesized permissions. Restricting writes in this way ensures the system can clean up files when applications are uninstalled.



来源:https://stackoverflow.com/questions/25469893/file-canwrite-says-true-but-i-cant-write-on-removable-storage-kit-kat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!