Skip to content

BalioFVFX/Android-Simple-File-Explorer-Library

Repository files navigation

Android-Simple-File-Explorer-Library

Simple, Responsive & Easy To Use Library For Android
Warning: This library uses external legacy storage! android:requestLegacyExternalStorage="true". Please read more about it here: https://developer.android.com/training/data-storage/use-cases#opt-out-scoped-storage

INTRODUCTION

Showing file explorer in Android has never been easier.


GETTING STARTED

GRADLE SETUP:

Step 1: Add it in your root build.gradle (Project) at the end of repositories

	allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}
Step 2: Add it in your build.gradle (Module:app)

	dependencies {
	        implementation 'com.github.BalioFVFX:Android-Simple-File-Explorer-Library:2.0.7'
	}

USAGE

Note: Before showing the file explorer you must ask for "WRITE_EXTERNAL_STORAGE" permission.

Permission Image

Showing the file explorer

Intent intent = new Intent(CONTEXT, SimpleFileExplorerActivity);
startActivityForResult(intent, REQUEST_CODE);

Disabling the select button for directories

Intent intent = new Intent(CONTEXT, SimpleFileExplorerActivity);
intent.putExtra(SimpleFileExplorerActivity.ENABLE_DIRECTORY_SELECT_KEY, false);
startActivityForResult(intent, REQUEST_CODE);
Note: By default you can select directories, however you may want to disable this functionality.

Getting the selected file absolute path

Note: Your activity must override the onActivityResult(); method.
    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        if(data != null){
            String selectedAbsolutePath = data.getStringExtra(SimpleFileExplorerActivity.ON_ACTIVITY_RESULT_KEY);
            Toast.makeText(CONTEXT, selectedAbsolutePath, Toast.LENGTH_SHORT).show();    
        }
    }

Note: Always check if the data is null, otherwise exception may occur.
For example if the user doesn't select a directory / file and closes the file explorer data will be null.

Changing the default icons with your custom drawables

SimpleFileResources.imageFileId = R.drawable.ic_my_custom_file;
SimpleFileResources.imageDirectoryId = R.drawable.ic_my_custom_directory;
If you want to use the default icons:
SimpleFileResources.imageFileId = null;
SimpleFileResources.imageDirectoryId = null;

END

You are free to include this library in your application. Credit is appreciated but it's not requiered.
Feel free to suggest new features or report problems by opening new issue or contacting me by email.