选择一个文件夹后
registerForActivityResult( new ActivityResultContracts.OpenDocumentTree ...
我正在接受写作许可
getContentResolver().takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
稍后在应用程序中,我已将文件写入用户选择的目录
saveDir = DocumentFile.fromTreeUri(App.getInstance(), Uri.parse(uriStringSavedInPrefs));
问题是:当我创建一个文件时,它创建成功
DocumentFile finalResFile =saveDir.createFile("image/*",resFileName);
但是后来我删除了它,它也被删除了
DocumentFile.fromTreeUri(App.getInstance(),finalResFile .getUri()).delete();
但是后来我尝试再次创建一个新文件,但出现错误
DocumentFile finalResFile =saveDir.createFile("image/*",someNewFileName);
Failed query: java.lang.SecurityException: Permission Denial: reading com.android.externalstorage.ExternalStorageProvider uri content://com.android.externalstorage.documents/tree/primary%3A.AndroidData/document/primary%3A.AndroidData/children from pid=32273, uid=10546 requires that you obtain access using ACTION_OPEN_DOCUMENT or related APIs
Failed to create document
为什么删除单个文件后写入权限会丢失?