Android6上的EACCES(权限被拒绝)

时间:2016-02-02 13:52:36

标签: java android-6.0-marshmallow permission-denied

您好我得到例外java.io.FileNotFoundException

  

打开失败:Android 6上的EACCES(权限被拒绝)。

我在运行时授予了READ_EXTERNAL_STORAGE权限,但仍然收到此错误。请帮忙。

 private void checkForPermissions() {

    // Here, thisActivity is the current activity
    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.READ_EXTERNAL_STORAGE)
            != PackageManager.PERMISSION_GRANTED) {

        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.READ_EXTERNAL_STORAGE)) {

            // Show an expanation to the user *asynchronously*  don't block
            // this thread waiting for the user's response! After the user
            // sees the explanation, try again to request the permission.

            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
                    PERMISSIONS_REQUEST_ACCESS_PHOTO);
        } else {

            // No explanation needed, we can request the permission.

            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
                    PERMISSIONS_REQUEST_ACCESS_PHOTO);
        }
    } else {
        openGalley();
    }
}

private void openGalley() {
    Intent galleryIntent = new Intent(
            Intent.ACTION_PICK,
            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    startActivityForResult(galleryIntent, rerquestCode);
}

0 个答案:

没有答案