Allow User To Select Path For Save File in Android -
i developing 1 application our client , there 1 little functionality stuck, need help,
scenarion: have developed 1 recycle view, users can see list of images , songs , videos per category, user have 1 option see or listen images, audio or video, , there option download it.
need @ have done 1 static path user can save files, our client wants allow users select path save files , need file dialog user can select location.
note: guys note 1 static path have done , working superb, storing path in local database can use later, remain how can allow user select location save file?
i think android directorychooser choose directory file save.
manifest
you need declare directorychooseractivity
, request 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 directory, start activity 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 constant integer identify request, e.g. 0 startactivityforresult(chooserintent, request_directory);
handle result in 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 } } }
Comments
Post a Comment