![](/img/trans.png)
[英]Coverity - Explicit null dereferenced (FORWARD_NULL) in contentResolver.delete()
[英]Android 10: contentResolver.delete() is not deleting file from the file system
我正在使用 MediaStore.Files 在 InternalStorage/Documents/MyFolderName/xyz.pdf 中創建我的文件
使用
ContentValues contentValues = new ContentValues();
contentValues.put(MediaStore.Files.FileColumns.DISPLAY_NAME, fileName);
contentValues.put(MediaStore.Files.FileColumns.MIME_TYPE, fileType);
contentValues.put(MediaStore.Files.FileColumns.IS_PENDING, 1);
contentValues.put(MediaStore.Files.FileColumns.RELATIVE_PATH, dstPublicDirectory + File.separator + dstSubDirectory);
// Getting content uri for the file
Uri dstFileUri = resolver.insert(MediaStore.Files.getContentUri("external"), contentValues);
我能夠創建 xyz.pdf 文件
但是,為了刪除我正在使用的那個文件
getActivity().getContentResolver().delete(fileUriToDelete, null, null);
以上內容已從 MediaStore.Files 的數據庫中刪除,但無法刪除文件系統中的該文件。
由於該文件仍在:InternalStorage/Documents/MyFolderName 這僅在 Android 10 中發生。在 Android 11 中,該文件將從文件系統以及 MediaStore.Files db 中刪除
[請確保將您的清單設置為與其相同,我面臨同樣的這個問題我的文件在 Android 11 上刪除,但在 Android 10 上沒有刪除,然后我啟用狀態並添加此標簽,並指定寫入權限<android:requestLegacyExternalStorage="true"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:ignore="ScopedStorage" android:maxSdkVersion="28"/>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.