file.canWrite()说:"真"但我不能移动存储写(奇巧) [英] file.canWrite() says "true" but I can't write on removable storage (kit kat)

查看:400
本文介绍了file.canWrite()说:"真"但我不能移动存储写(奇巧)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到来自摄像机的意图,在这条道路合影留念:结果
/storage/extSdCard/DCIM/Camera/photoCaptured.jpg

和我想要的图像来调整(已经这样做),并在同一路径覆盖......结果
我能做到这一点的2.3,4.1和4.3,但......不是在4.4

所以...也许问题是这个文件夹的权限,所以我这个检查...

 如果(myFile.canWrite()){
    Log.e(myMethodToSave,你有权限:+ MYFILE);
}其他{
    Log.e(myMethodToSave,算了吧!:+ MYFILE);
}

...我有写权限,但4.4,表示拒绝权限结果
为什么呢?结果
我怎样才能解决这个问题?

EDITED

 萨利达=新的FileOutputStream(MYFILE); //只在奇巧的错误
bitmap.com preSS(Bitmap.Com pressFormat.JPEG,70,萨利达);


解决方案

从的 http://source.android.com/devices/tech/storage/index.html

该WRITE_EXTERNAL_STORAG​​E权限只能授予一个设备上的主要外部存储的写访问。应用决不允许所允许的合成权限写入到二次外部存储设备,除了在其特定的包目录。以这种方式限制写入保证了系统可以清理文件时应用程序卸载。

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

解决方案

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.

这篇关于file.canWrite()说:"真"但我不能移动存储写(奇巧)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆