I am developing one application for our client and there is one little functionality where we are stuck, so need your help,
Scenarion: We have developed one recycle view, from where users can see list of images and songs and videos as per category, now User have one option to see or listen images, audio or video, and also there is another option to download it.
Need Help @ We have done this with one static path where user can save all files, but our client wants to allow users to select path to save files and for that we need file dialog from where user can select location.
Note: Guys note that for one static path we have done this and it is working superb, also we are storing that path in local database so we can use it later, So now just remain is how can we allow user to select location for save file?
id. mylist); myList = new ArrayList<String>(); File directory = Environment. getExternalStorageDirectory(); file = new File( directory + "/Test" ); File list[] = file. listFiles(); for( int i=0; i< list.
From the main menu, go to View -> Tool Windows -> Device File Explorer. You can then select your device / emulator from the drop down list. To access /data/user/0/com. example.
i think Android DirectoryChooser is help you for choose directory for file save.
Manifest
You need to declare the DirectoryChooserActivity
and request the android.permission.WRITE_EXTERNAL_STORAGE
permission.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
...
<application>
<activity android:name="net.rdrei.android.dirchooser.DirectoryChooserActivity" />
</application>
Activity
To choose a directory, start the activity from your app logic:
final Intent chooserIntent = new Intent(this, DirectoryChooserActivity.class);
final DirectoryChooserConfig config = DirectoryChooserConfig.builder()
.newDirectoryName("DirChooserSample")
.allowReadOnlyDirectory(true)
.allowNewDirectoryNameModification(true)
.build();
chooserIntent.putExtra(DirectoryChooserActivity.EXTRA_CONFIG, config);
// REQUEST_DIRECTORY is a constant integer to identify the request, e.g. 0
startActivityForResult(chooserIntent, REQUEST_DIRECTORY);
Handle the result in your onActivityResult
method:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_DIRECTORY) {
if (resultCode == DirectoryChooserActivity.RESULT_CODE_DIR_SELECTED) {
handleDirectoryChoice(data
.getStringExtra(DirectoryChooserActivity.RESULT_SELECTED_DIR));
} else {
// Nothing selected
}
}
}
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