Giter Club home page Giter Club logo

android11filepicker's Introduction

Android FilePicker

Description

This app can make the file picking process easy, which allows you to select Pictures, Videos, and Documents. Also, that has Capturing Photo/Video option. For using this library, you need to migrate your project to AndroidX(If your project is not migrated to AndroidX).

This works without MANAGE_EXTERNAL_STORAGE permission Since it's very useful when you publish the app on Google Plsy Strore.

Getting Started

To add this library to your project, please follow below steps

Add this in your root build.gradle file (project level gradle file):

allprojects {
    repositories {
        maven { url "https://www.jitpack.io" }
    }
}

buildscript {
    repositories {
        maven { url "https://www.jitpack.io" }
    }
}

Then, Add this in your root build.gradle file (app level gradle file):

add implementation 'implementation 'com.github.braver-tool:Android11FilePicker:1.0.0' to your build.gradle dependencies block.

for example:

dependencies {
  implementation 'com.github.braver-tool:Android11FilePicker:1.0.0'
}

Key Features :

  • Kotlin language supported
  • Fully Handled Android's Dangerous Permissions
  • Compressing option for selected images included,
  • To Preview your selected images using 'PhotoView'
  • To Preview your selected videos using exoplayer
  • Can pick any non-media files like PDF,Doc,Txt files without using MANAGE_EXTERNAL_STORAGE permission
  • Supports upto Android 12 and SplashScreen API

This library compatible with Android 6 and above

Version Compatibility

It depends on your targetAPI:

  • targetAPI <= 28, you are fine ;)
  • targetAPI >= 29, please enable requestLegacyExternalStorage on your Manifest.xml file

How to use the included SD-card picker:

Include a provider element

Due to changes in Android 6.0 Marshmallow, bare File URIs can no longer be returned in a safe way. This change requires you to add an entry to your manifest.

NOTE: If you have an existing content provider in your app with the same authority you will have a conflict.

    <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.provider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/provider_paths"
                tools:replace="android:resource" />
        </provider>

Permissions Needed :

  • android.permission.READ_EXTERNAL_STORAGE
  • android.permission.CAMERA
  • android.permission.RECORD_AUDIO

Include the camera activity

**NOTE: The theme set in the manifest is important.

    <activity
       android:name="com.braver.tool.picker.CameraActivity"
       android:label="@string/app_name"
         android:theme="@style/Theme.FilePicker">
    </activity>

Handling the ActivityResult

You can use the included utility method to parse the activity result:

 activityResultLauncherForGallery = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
            if (result.getResultCode() == RESULT_OK && result.getData() != null) {
             Uri selectedMediaUri = result.getData().getData();
             File imageFile = new BraveFilePicker().setActivity(PickerActivity.this).setIsCompressImage(false).setIsTrimVide(false).setFileType(BraveFileType.IMAGE).setDestinationFilePath(AppUtils.getRandomImageFileName(PickerActivity.this)).setContentUri(selectedMediaUri).getSourceFile();
             // Do something with the result...
            }
        });

Want to customize further?

Sample project is here(https://github.com/braver-tool/Android11FilePicker)

Usage

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.