您的位置:首页 > 移动开发 > Android开发

android.system.ErrnoException: open failed: ENOENT (No such file or directory) 07-19 20:27:45.011 66

2016-07-19 20:40 591 查看
在操作安卓版本23+的文件读取时,不仅要在maniests中声明,还要在代码中动态声明:

private static final int REQUEST_EXTERNAL_STORAGE = 1;
private static String[] PERMISSIONS_STORAGE = {
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE};

/**
* 8      * Checks if the app has permission to write to device storage
* 9      *
* 10      * If the app does not has permission then the user will be prompted to
* 11      * grant permissions
* 12      *
* 13      * @param activity
* 14
*/
public static void verifyStoragePermissions(Activity activity) {
// Check if we have write permission
int permission = ActivityCompat.checkSelfPermission(activity,
Manifest.permission.WRITE_EXTERNAL_STORAGE);

if (permission != PackageManager.PERMISSION_GRANTED) {
// We don't have permission so prompt the user
ActivityCompat.requestPermissions(activity, PERMISSIONS_STORAGE,
REQUEST_EXTERNAL_STORAGE);
}
}


然后直接调用就可以了。

来源出处:http://www.cnblogs.com/zzw1994/p/5021118.html

非常感谢,忙了一下午,终于解决了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: