Giter Site home page Giter Site logo

atwa / filepicker Goto Github PK

View Code? Open in Web Editor NEW
85.0 3.0 7.0 172 KB

Android file and image picker library without permissions.

License: Apache License 2.0

Kotlin 100.00%
android filepicker filepicker-library kotlin library camera-capture image-picker image-picker-android image-picker-library no-permissions

filepicker's Introduction

FilePicker

Android library to facilitate files and image picking up process whether from storage or camera and ability to convert them to request bodies without permission.

The goal of this library is to get rid of the hassle of file picking up handling and reduce effort made in uploading them to server without the need to ask use for a single permission.

Features:

  • Launch different file types picking requests (Image ,Video ,Pdf and File for general).
  • Get a callback with related meta according to the request type.
  • Meta can be (fileName,size in Kb, bitmap and file object).
  • Convert picked up files to request bodies to use them with api requests to upload them to server.
  • Not a single permission is required.

Dependency :

allprojects {
  	repositories {
  		...
  		maven { url 'https://jitpack.io' }
  	}
  }
dependencies {
      implementation 'com.github.atwa:filepicker:1.0.7'
  }

Usage :

  • Initialize instance in activity/fragment as member variable.

    private val filePicker = FilePicker.getInstance(this)
    
  • Image picking

    fun pickImage() {
          filePicker.pickImage() { meta ->
              val name : String? = meta?.name
              val sizeKb : Int? = meta?.sizeKb
              val file : File? = meta?.file
              val bitmap : Bitmap? = meta?.bitmap
          }
      }
    
  • Image capture

    fun captureImage() {
          filePicker.captureCameraImage() { meta ->
              val name : String? = meta?.name
              val sizeKb : Int? = meta?.sizeKb
              val file : File? = meta?.file
              val bitmap : Bitmap? = meta?.bitmap
          }
      }
    
  • Pdf picking

    fun pickPdf() {
          filePicker.pickPdf() { meta ->
              val name: String? = meta?.name
              val sizeKb: Int? = meta?.sizeKb
              val file: File? = meta?.file
          }
      }
    
  • Video picking

    fun pickVideo() {
          filePicker.pickVideo() { meta ->
              val name: String? = meta?.name
              val sizeKb: Int? = meta?.sizeKb
              val file: File? = meta?.file
              val thumbnail: Bitmap? = meta?.thumbnail
          }
      }
    
  • File picking

    fun pickFile() {
          filePicker.pickFile() { meta ->
              val name: String? = meta?.name
              val sizeKb: Int? = meta?.sizeKb
              val file: File? = meta?.file
          }
      }
    
  • File picking from Initial directory

    fun pickFile() {
          filePicker.pickFile("path") { meta ->
              val name: String? = meta?.name
              val sizeKb: Int? = meta?.sizeKb
              val file: File? = meta?.file
          }
      }
    
  • File converting to request body

    fun convertFile() {
          val file: File = File("file")
          val requestBody: RequestBody = FileConverter.getInstance()
              .toRequestBody(file, FileConverter.getInstance().fileMediaType)
      }
    

Version history

Version Release note
1.0.0 Initial release.
1.0.1 Increase buffer size (8GB) to be larger for better performance.
1.0.3 Fix bug : LifecycleOwner Activity is attempting to register while current state is RESUMED.
1.0.4 Enhancement : Avoid possible activity reference leaking.
Feature : Implement camera image picker.
1.0.5 Feature : Support fragments.
Feature : Implement file picking from initial directory.
fix : obsolete app icon unintended overriding.
1.0.6 Enhancement : Add file extension to video files and images picked from camera.
1.0.7 Fix bug : Captured image file from camera is corrupted.
1.0.8 Enhancement : High quality camera image.
1.0.9 Refactor : Replaced coroutines by Executor & Handler.
Update : Updated compileSdk to 34.
1.0.10 Fix bug : capture image issue for the second time.
Fix bug : installing multiple apps using the library on the same device.
Close issue : #25

Contribution

Please feel free to make a pull request or fork.

Rate

If you find this repository useful please give it a star .

filepicker's People

Contributors

atwa 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

Watchers

 avatar  avatar

filepicker's Issues

[Feature request] Get photo from camera

Would be great to have ability to take photo from camera using this library

val cameraIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE).apply {
addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
putExtra(MediaStore.EXTRA_OUTPUT, outputUri)
}

And interface like:
fun pickImageFromCamera(outputUri: Uri, onImagePicked: (Pair<Bitmap?, File?>?) -> Unit)

use in fragment

Hi Atwa
how to use this methods in fragment?
when I use in fragment , I get this Err:

java.lang.IllegalStateException: LifecycleOwner MyPakageName.ui.MainActivity@69347ae is attempting to register while current state is RESUMED. LifecycleOwners must call register before they are STARTED.

thanks

Camera capture image quality

@Atwa How to increase captureCameraImage quality like it giving me image in 40 KB which is not good in quality…
I tested it on emulator and on real device Android 9.0
Gallery selection image size is perfect and quality is also but capture image quality is not good.

Bug in v1.0.9

In last version when you try to take a second picture using the camera, this error appears. In v1.0.8 is working correctly I guess its because of compileSdk 34

Writing exception to parcel (Ask Gemini) java.lang.SecurityException: Permission Denial: writing androidx.core.content.FileProvider uri content://com.atwa.filepicker.provider/cache/17164781527943286665285211823.jpg from pid=23570, uid=10099 requires the provider be exported, or grantUriPermission() at android.content.ContentProvider.enforceWritePermissionInner(ContentProvider.java:1167) at android.content.ContentProvider.semEnforceWritePermission(ContentProvider.java:1093) at android.content.ContentProvider$Transport.enforceWritePermission(ContentProvider.java:836) at android.content.ContentProvider$Transport.enforceFilePermission(ContentProvider.java:803) at android.content.ContentProvider$Transport.openAssetFile(ContentProvider.java:609) at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:284) at android.os.Binder.execTransactInternal(Binder.java:1375) at android.os.Binder.execTransact(Binder.java:1311)

registerForActivityResult should be scalled before your activity is created

I'm getting error when launch a picker

LifecycleOwner MyActivity is attempting to register while current state is RESUMED. LifecycleOwners must call register before they are STARTED.

Reason: Related to android documentation, registerForActivityResult() is safe to call before your fragment or activity is created

How to do it for this library?

app icon override

Hi Atwa,
There is a problem with ic_launcher under anydpi-v26 folders that override icon apps when using the library, I think ic_launcher should be removed as it's a library project.
what do you think?
Regards

Very bad quality when taking a picture

I tried the code example to take a picture but the output is a very small image, despite of in preview its showing correctly. Output is a 162x289 image of ~43KB (imageMeta.getSizeKb())

Code used:

filePicker.captureCameraImage(imageMeta -> { sendFile(ChatMessage.TYPE.image, imageMeta.getName(), imageMeta.getFile()); return null; });

issue with readme

Capture

public abstract fun toRequestBody(
    file: File,
    type: MediaType?
): RequestBody

not

public abstract fun toRequestBody(
type: MediaType?,
    file: File
): RequestBody

as readme told

Thank you for helping me with this great library

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.