ajayasija23 / FilePicker

A simple library to pick any kind of file

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Preview

FilePicker

FilePicker is an Android Library that lets you choose any kind of file easyly. It handles the storage permission itself.

Minimum Sdk Version

Api Level 19 or Above

Max Sdk Version

Api Level 30

Installation

Add the following code snippet in your project level gradle file

repositories {
    ...
    maven { url 'https://jitpack.io' }
  }

Add the dependency in your app gradle

dependencies {
       ...
      implementation 'com.github.ajayasija23:FilePicker:1.0.1' //choose latest version
  }

Usage

Start FilePickerActivity and pass the MimeType of the target file

Intent intent=new Intent(this, FilePickerActivity.class);
intent.putExtra("multiple",true);
intent.putExtra("type","*/*");
startActivityForResult(intent,REQUEST_CODE);

Override the onActivityResult

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode==REQUEST_CODE&&resultCode==RESULT_OK&&data!=null){
        if (data.getData()!=null){
            File file=FileUtils.getFile(this,data.getData());
            selectedFiles.add(file.getName());
        }
        if (data.getClipData()!=null){
            for(int i = 0; i < data.getClipData().getItemCount(); i++) {
                Uri uri = data.getClipData().getItemAt(i).getUri();
                File file=FileUtils.getFile(this,uri);
                selectedFiles.add(file.getName());
            }
        }
    }
}

About

A simple library to pick any kind of file

License:GNU General Public License v3.0


Languages

Language:Java 100.0%