Android file explorer

I have to implement file browser in my on going project to pick single/multiple image file for which i have to do all those things browse to roots and check weather current browsing is file or directories etc…. so i made a simple library for browsing file which provides choice to pick single or multiple file.

Now if you have same scenario and thinking of “how to make file explorer in android”.Then, here i am with solution to implement file explorer with very few lines codes. just few lines of code.

Here are the steps you need to follow

1) Pull the library from github and make a project from it.

2) Then Simply call the intent from your project like this


Intent intent = new Intent(FilebrowserDemoActivity.this,
					FileBrowserActivity.class);
			intent.putExtra(FileBrowserActivity.BROWSE_MODE,
					FileBrowserActivity.SINGLE);
			startActivityForResult(intent, REQUEST_FILE_BROWSE);

Note: for picking multiple file send intent string extra

intent.putExtra(FileBrowserActivity.BROWSE_MODE,
					FileBrowserActivity.MULTIPLE);

instead of

intent.putExtra(FileBrowserActivity.BROWSE_MODE,
					FileBrowserActivity.SINGLE);

3) Define onActivityResult like this to get the selected file path


     @Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		if (resultCode == Activity.RESULT_OK
				& requestCode == REQUEST_FILE_BROWSE) {
			
			ArrayList<String> selectedImagePath = new ArrayList<String>();
			selectedImagePath = data
					.getStringArrayListExtra(FileBrowserActivity.RESULT);
			for (String imagePath : selectedImagePath) {
				Log.v(TAG, imagePath);
				
				
			}
			
		}

	};

Note : Don’t forget to add activity in android manifest file like this

<activity android:name="com.example.filebrowser.FileBrowserActivity"></activity>

Enough for implementing file browser in your project. if you got any problem while implementing then don worry,source with and demo project is in my github account.

Advertisements