No such file or Directory only in Android 6.0

前端 未结 4 1074
感情败类
感情败类 2021-01-27 19:09

Below code is working fine on pre-Marshmallow devices but not in Marshmallow.

These are the permissions in Manifest



        
4条回答
  •  误落风尘
    2021-01-27 19:42

    give read write permissions on run time for marshmallow or newer version. Do like below:-

    String[] PERMISSIONS = new String[]{ Manifest.permission.WRITE_EXTERNAL_STORAGE};
    
    if (!hasPermissions(this, PERMISSIONS)) {
                ActivityCompat.requestPermissions(this, PERMISSIONS, 11);
                return;
            }
    
    private boolean hasPermissions(Context context, String... permissions) {
            if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && context != null && permissions != null) {
                for (String permission : permissions) {
                    if (ActivityCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) {
                        return false;
                    }
                }
            }
            return true;
        }
    

提交回复
热议问题