Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete a file using Storage Access Framework?

Tags:

android

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.

like image 384
Millo Varantz Avatar asked Oct 31 '15 11:10

Millo Varantz


People also ask

How do I use storage access framework?

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.

What is SAF Android?

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.

What is storage access framework (SAF)?

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.

How to delete a file from a storage account?

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.

How do I create a delete file request?

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.

What happens when a file is successfully deleted?

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.


1 Answers

Use the application context to call the context resolver.

DocumentsContract.deleteDocument(getApplicationContext().getContentResolver(),uri)

like image 111
Chisom Maxwell Avatar answered Sep 19 '22 07:09

Chisom Maxwell