How to Use the New Sd Card Access API Presented For Android 5.0 (Lollipop)

How to use the new lollipop SD Card Access API to delete and modify files

The link you mentioned (How to use the new SD-Card access API presented for Lollipop) gives instructions on how to prompt user to choose the root directory using ACTION_OPEN_DOCUMENT_TREE.

After the user chooses the root node then your code will have a DocumentFile that represents the root node. You say you already have the file path. If so then use the segments of the file path and follow the path down the hierarchy using DocumentFile.html#listFiles().

You'll finally have the DocumentFile that represent the file you want to delete, then call DocumentFile.html#delete()

Saving files to SD card on Android Lollipop

It's impossible. User should choose directory using android's file picker. The only way to get access to folder is using:

Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
startActivityForResult(intent, 42);

Because file is provided by Storage Access Framework DocumentsProvider. Actually it could return some Uri from 3-rd party app, which is not real file, but some entity, which 3-rd party app present as file.



Related Topics



Leave a reply



Submit