Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to browse folder in android and get the path of folder selected

Tags:

java

android

When I click a button,show a file browser,I can choose a folder and return it's path.I get this path to copy file to that path.

But I have no idea of How I could implement this.

I have yet looking for this question in Stackoverflow but I haven't find a clear answer to my question.

I saw some libary of filebrowserview like "https://github.com/psaravan/FileBrowserView",but not work.

like image 249
I DAE Avatar asked Aug 11 '15 09:08

I DAE


People also ask

How do you go to a folder path?

To view the full path of a folder: Click the Start button and then click Computer, click to open the location of the desired folder, and then right-click to the right of the path in the address bar.

How do I get a list of images in a specific folder on Android?

You can use below code to get all images from specific folder. 1) First you need to define File object to get the storage and appened the name of the folder you want to read. File folder = new File(Environment. getExternalStorageDirectory().

How do I open file manager in android programmatically?

Intent intent = new Intent(Intent. ACTION_GET_CONTENT); intent. setType("*/*"); Intent i = Intent. createChooser(intent, "View Default File Manager"); startActivityForResult(i, CHOOSE_FILE_REQUESTCODE);


1 Answers

Use intent for that!

First start start activity for result like this:

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
startActivityForResult(intent, PICKFILE_REQUEST_CODE);

Override this method in your activity, it will get called when activity you just started returns. You can handle result codes such as canceled or successful.

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
     String Fpath = data.getDataString();
    //TODO handle your request here
    super.onActivityResult(requestCode, resultCode, data);
}

Another approach is to use library such as NoNonsense-FilePicker.

like image 167
Adam Fręśko Avatar answered Oct 30 '22 10:10

Adam Fręśko