Android: Directory and file chooser android library -
i'm using afilechooser android library project in app select file external storage. doesn't seem pick directory let user select download location download files. there android library project support both pick file , pick directory?
i understand there multiple questions have been answered here either file chooser or directory chooser after extensive search couldn't find 1 both directory , file chooser. appreciated.
i have no android library project, can make own file chooser next code. code ask chose file browser, when select file in file browser you'll path in onactivityresult function in filepath string.
create public:
private static final int activity_choose_file = 3;
when button clicked can call this:
intent choosefile; intent intent; choosefile = new intent(intent.action_get_content); choosefile.settype("file/*"); intent = intent.createchooser(choosefile, "choose file"); startactivityforresult(intent, activity_choose_file);
you can catch directory code :
protected void onactivityresult(int requestcode, int resultcode, intent data) { if (resultcode != result_ok) return; string path = ""; if(requestcode == activity_choose_file) { uri uri = data.getdata(); string filepath = getrealpathfromuri(uri); } } public string getrealpathfromuri(uri contenturi) { string [] proj = {mediastore.images.media.data}; cursor cursor = getcontentresolver().query( contenturi, proj, null, null,null); if (cursor == null) return null; int column_index = cursor.getcolumnindexorthrow(mediastore.images.media.data); cursor.movetofirst(); return cursor.getstring(column_index); }
edit: if not want use external file browser, can import android library project: https://code.google.com/p/afiledialog/
Comments
Post a Comment