Android 8.0 FileObserver 监听不到文件变化的原因

FileObserver 添加了如下权限:



并且动态申请了权限依旧监听不到文件变化的事件:

    private boolean checkPermission() {
        //检测是否有写的权限
        List permissionsList = new ArrayList();

        if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            permissionsList.add(Manifest.permission.READ_EXTERNAL_STORAGE);
        }
        if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            permissionsList.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
        }

        if (permissionsList.size() > 0) {
            ActivityCompat.requestPermissions((Activity) this, permissionsList.toArray(new String[permissionsList.size()]),
                    1);
            return false;
        }
        return true;
    }

应用需要系统权限才可以。

你可能感兴趣的:(Android 8.0 FileObserver 监听不到文件变化的原因)