15

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?

vitr
  • 6,766
  • 8
  • 30
  • 50
Vickyexpert
  • 3,147
  • 5
  • 21
  • 34
  • 1
    Releted Post- http://stackoverflow.com/questions/7856959/android-file-chooser – user3161880 Sep 13 '16 at 05:19
  • I already have checked this, but it is file selector not location selector, I don't have to select file, I have to select location where file can be store – Vickyexpert Sep 13 '16 at 05:21
  • Good Question. As per my knowledge you need to search for list the folders on particular storage(internal/external). Then on selection of that folder you need to again list folders in it. You can do that way. I have found example for you but not sure it will working or not. http://developer.samsung.com/technical-doc/view.do;jsessionid=8881C1BE25C54CBA8427A185E0E4DBF3?v=T000000089 – Shabbir Dhangot Sep 13 '16 at 05:22
  • @ShabbirDhangot thanks, currently I am looking for that only even I am thinking to go with file explorer where I can apply some logic to select only folder instead of file, also let me check your link – Vickyexpert Sep 13 '16 at 05:24
  • i too, i newly become also a photographer :D so using LAN options, i transfers GIGs of image to my mobile device, and when i'm on the way to work, check and share them on instagram, recently i find the need to bulk modify images, with so many searching and trial and error in several days, which would take only 2 hour without research on .net win app, i wrote selecting document, load all files, modify files, but i couldn't find a way to save file, also all the resources out there about converting uri to absolute pass, for all platforms, failed for me, i'm wonder how many application still runs – Hassan Faghihi Jul 23 '18 at 07:10
  • .... the rest, so i can't let the image to store any where they want, i need to categories them in different places, so i remove them without involving other images, naming folder, so i know which tag apply without going through the process of finding and opening original file EXIF info, and overcome storage limitation, and many other reason, that the directory should be selectable, and at some point maybe user create a folder under another folder, for some other user needs that i didn't take into account... , the current android File Storage System lacks these understandings... – Hassan Faghihi Jul 23 '18 at 07:18

1 Answers1

12

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
        }
    }
}
prakash ubhadiya
  • 1,242
  • 1
  • 12
  • 24