安卓6.0打开失败:EACCES(权限被拒绝)
我不得不添加使用-许可
包括WRITE_EXTERNAL_STORAGE$c$c>,MOUNT_UNMOUNT_FILESYSTEMS$c$c>,READ_EXTERNAL_STORAGE$c$c>以的AndroidManifest.xml
。
I had add uses-permission
including WRITE_EXTERNAL_STORAGE
,MOUNT_UNMOUNT_FILESYSTEMS
,READ_EXTERNAL_STORAGE
to AndroidManifest.xml
.
当我跑在Nexus5(Android6.0)我的应用程序,它抛出一个异常,如下:
When I ran my app in Nexus5(Android6.0),it threw a exception as below:
java.io.IOException异常:打开失败:EACCES(权限被拒绝)
和我尝试另一个Android手机(Android5.1),一切都OK.Here是在code:
And I tried another Android phone(Android5.1),everything was OK.Here's the code:
private File createImageFile() throws IOException {
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(imageFileName, ".jpg", storageDir);
currentPhotoPath = image.getAbsolutePath();
return image;
}
难道Android的6.0有关于许可的区别?
Does Android 6.0 have difference about permission?
的Android增添了新的许可模式为Android 6.0(MARSHMELLOW)。
Android added new permission model for Android 6.0 (Marshmellow).
http://www.captechconsulting.com/blogs/runtime-permissions-best-practices-and-how-to-gracefully-handle-permission-removal
所以,你必须检查运行权限
:
什么是运行权限?
使用的Android 6.0棉花糖,谷歌推出了新的许可模式,让用户能够更好地理解为什么一个应用程序可以请求特定的权限。而不是盲目地接受所有权限,在安装时用户,用户通过提示接受的权限,因为他们在应用程序的使用成为必需。
With Android 6.0 Marshmallow, Google introduced a new permission model that allows users to better understand why an application may be requesting specific permissions. Rather than the user blindly accepting all permissions at install time, the user is now prompted to accept permissions as they become necessary during application use.
当执行新的模式?
它不要求完全支持,直到您选择定位在你的应用程序版本23。如果你的目标版本22或以下时,你的应用程序将要求所有权限在安装时,就像它会运行下面棉花糖操作系统的任何设备。
it doesn’t require full support until you choose to target version 23 in your application. If you are targeting version 22 or below, your application will request all permissions at install time just as it would on any device running an OS below Marshmallow.
此信息是从这里:
请查看如何从这个链接实现:
Please check How to implement from this link :
http://www.captechconsulting.com/blogs/runtime-permissions-best-practices-and-how-to-gracefully-handle-permission-removal