How can I delete files using Storage Access Framework in Android? I found this method in the documentation but couldn't get it working: DocumentsContract.deleteDocument(ContentResolver, Uri);
Can I delete a specific file without asking user what to delete with this?
Edit:
I tried getting file uri with Uri.fromFile, failed with null pointer exception. I tried getting file uri by using ACTION_OPEN_DOCUMENT but it asks user to select a file (i want to specify the file myself). Even like this it didn't work, giving exception and telling me delete not supported.
The Storage Access Framework should subsequently display the “Save to” storage picker user interface as illustrated in Figure 70-2. From this menu, select the Drive option followed by My Drive and navigate to a suitable location on your Google Drive storage into which to save the file.
Android 4.4 (API level 19) introduces the Storage Access Framework (SAF). The SAF makes it simple for users to browse and open documents, images, and other files across all of their preferred document storage providers.
Android 4.4 (API level 19) introduces the Storage Access Framework (SAF). The SAF makes it simple for users to browse and open documents, images, and other files across all of their their preferred document storage providers. A standard, easy-to-use UI lets users browse files and access recents in a consistent way across apps and providers.
The Delete File operation immediately removes the file from the storage account. The Delete File request is constructed as follows. HTTPS is recommended. Replace the path components shown in the request URI with your own, as follows: The name of your storage account. The name of your file share. Optional. The path to the parent directory.
The Delete File request is constructed as follows. HTTPS is recommended. Replace the path components shown in the request URI with your own, as follows: The name of your storage account. The name of your file share.
When a file is successfully deleted, it is immediately removed from the storage account's index and is no longer accessible to clients. The file's data is later removed from the service during garbage collection.
Use the application context to call the context resolver.
DocumentsContract.deleteDocument(getApplicationContext().getContentResolver(),uri)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With