Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which Android intent to use to get the 'Save to device' behaviour in dropbox app?

Currently I am able to implement store and retrieve file from Google Drive without issue but I want to add an additional functionality which is to save the file directly to local storage.

In dropbox app, if you try to export a file and in the chooser select 'Save to device', it will show something like below:

enter image description here

At first I thought they created the activity themselves but it looks very similar to the ACTION_GET_CONTENT intent that I am using.. My code is just something like:

 Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
 intent.setType("application/*");
 startActivityForResult(intent, 0);

which show something like below:

enter image description here

That makes me think that Dropbox app must be using an Android intent to save file to local storage like ACTION_ADD_CONTENT or something.. Or am I wrong?

Thanks.

like image 358
Bruce Avatar asked Apr 17 '16 10:04

Bruce


1 Answers

Kuffs has it right — you are seeing the UI for the Storage Access Framework. Specifically, for a "save as" sort of feature, use ACTION_CREATE_DOCUMENT. You will get back a content: Uri for the location that the user chose, and you can use a ContentResolver and openOutputStream() to write your data to that location.

like image 118
CommonsWare Avatar answered Sep 18 '22 01:09

CommonsWare