无法使用getExternalFilesDir()方法在外部存储上创建专用目录

时间:2018-05-02 03:43:59

标签: android android-external-storage

我正试图通过此代码在SD卡上创建私人目录,

 if(Util.isExternalStorageWritable()) {

        int writePermission = ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
        int readPermission = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);
        if (writePermission == PackageManager.PERMISSION_GRANTED && readPermission == PackageManager.PERMISSION_GRANTED) {
            File folder = new File(AddWazaif.this.getExternalFilesDir(Environment.DIRECTORY_PICTURES), "directory");
            if (!folder.exists()) {
                folder.mkdirs();
            }
        }
}

但未创建目录。仅使用此方法Environment.getExternalStorageDirectory()创建的目录。但我想只有私人目录所以当应用程序去卸载目录也被删除。请帮忙。

  

清单:

<uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

目录结构: enter image description here

0 个答案:

没有答案