Git Product home page Git Product logo

unicornfilepicker's Introduction

Unicorn File Picker

CircleCI Download Android Arsenal

Unicorn File Picker is a library designed to package a powerful file selector for android. You can:

  • Start the file picker activity from any activity or fragment
  • Select single or multiple files
  • Use as a Directory Picker
  • Filter out files you want to display
  • Add custom theme or use default theme options (Light & Dracula)
  • And much more which you have to try out for yourself
Unicorn Dracula Unicorn Default Custom Theme

Download

Gradle:

repositories {
    maven { url ‘https://jitpack.io’ }
}

dependencies {
    implementation 'com.github.abhishekti7:UnicornFilePicker:$latest_version'
}

How do I use Unicorn File Picker?

Permission

The library requires two permissions:

  • android.permission.READ_EXTERNAL_STORAGE
  • android.permission.WRITE_EXTERNAL_STORAGE

If you are targeting Android 6.0+, you need to handle runtime permission request before next step.

Also, don't forget to add requestlegacyexternalstorage=true for Android 10.

Simple usage snippet


Start UnicornFilePicker from current Activity or Fragment:

UnicornFilePicker.from(MainActivity.this)
                    .addConfigBuilder()
                    .selectMultipleFiles(false)
                    .showOnlyDirectory(true)
                    .setRootDirectory(Environment.getExternalStorageDirectory().getAbsolutePath())
                    .showHiddenFiles(false)
                    .setFilters(new String[]{"pdf", "png", "jpg", "jpeg"})
                    .addItemDivider(true)
                    .theme(R.style.UnicornFilePicker_Dracula)
                    .build()
                    .forResult(Constants.REQ_UNICORN_FILE);

Themes

There are two built-in themes you can use to start UnicornFilePicker:

  • R.style.UnicornFilePicker_Default (light mode)
  • R.style.UnicornFilePicker_Dracula (dark mode)

You can also define your own custom theme.

Receive Result

In onActivityResult() callback of the starting Activity or Fragment:

List<String> mSelected_files;

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_CODE_CHOOSE && resultCode == RESULT_OK) {
        ArrayList<String> files = data.getStringArrayListExtra("filePaths");
        for(String file : files){
            Log.e(TAG, file);
        }
    }
}

PLEASE NOTE:

API >= 21 && API <=28

The file picker works great on legacy android versions and there's is no need for any additional configuration.

API 29

You need to add the following line to your manifest file if you want to use this picker on android 10 for atleast a few months.

    android:requestLegacyExternalStorage="true"

This line indicates to the operating system that we want to opt out of the new Scoped Storage system.

API > 29 (WIP)

Unfortunately this library has no stable support for file access on Android 11+. Behaviour noticed on Android 11 -> While the file picker works, the only files that are displayed are the media files which include images, videos, audio, etc. This is because of the introduction of the Google's infamous new storage model called Scoped Storage which aims to improve file security. You can read all about this here: Scoped Storage

This feature is currently a work-in-progress along with many other awesome things on the roadmap. If you feel you can add value to this feature then please see the section on Contributing.


Contributing

UnicornFilePicker is an Open Source Project

LICENSE

Copyright [2021] [Abhishek Tiwari]

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

unicornfilepicker's People

Contributors

abhishekti7 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

unicornfilepicker's Issues

Should Add File Delete option

Actuall i am using it in my new app and i think you should add delete file feature also it will helpful for use to delete file without going to device file manger

SDK 30 file issue - not showing

Hi, I really love your design for this file picker.
However, the project that I implemented with this library cannot find document-related file such as .pdf, .doc, .xlsx, .zip , etc.

I am now using SDK 30, only image/video-related file displayed.
Do you mind to help me to check it out?

showOnlyDir not implemented ??

Hi,
I appreciate your work : this chooser is fine and light, easy to implement !
But it seems that setShowOnlyDir(true) is not working (this parameter not recognized at compile time)
Is this functionality implemented ?

Using as part of existing view

is it possible to move this into a View?

For example, as an embedded file view in an app, similar to what PowerAmp does

Eg

FileManager fv = new FileManager(context);
// set options for file manager
fileManagerContainer.addView(fv);

REQUEST_CODE_CHOOSE constant unresolved in Kotlin translation

Hi,
I'm writing my program in Kotlin, so I had it translated by AndroidStudio, but the IDE cannot recognize this constant. Where do I find the declaration? The Kotlin adaptation of the function is below:

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == REQUEST_CODE_CHOOSE && resultCode == RESULT_OK) {
val files = data?.getStringArrayListExtra("filePaths")
for (file in files!!) {
Log.e("tag",file)
}
}
}

Thanks a lot in advance!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.