码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2017-10-25 15:14:56      阅读:423      评论:0      收藏:0      [点我收藏+]

标签:cep   verify   class   nal   col   cti   director   user   读取   

在操作安卓版本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);
        }
    }

 

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

标签:cep   verify   class   nal   col   cti   director   user   读取   

原文地址:http://www.cnblogs.com/zhujiabin/p/7728561.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!