ImagePickerUtil
himangipatel
31
Visit GitHub RepoImage Pickers

ImagePickerUtil

A Imagepicker which allows to select images or capture from camera with permission

Developed by

Himangi Patel

Features

Easy to Implement.
No permissions required.
Allow Crop
Compress image

Installation

Add repository url and dependency in application module gradle file:

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

dependencies {
        compile 'com.github.himangipatel:ImagePickerUtil:v2.1'
}

Usage

1. Start by creating an instance of FilePickUtils and LifeCycleCallBackManager.

  FilePickUtils filePickUtils = new FilePickUtils(this, onFileChoose);;
 LifeCycleCallBackManager lifeCycleCallBackManager = filePickUtils.getCallBackManager();

2. Callback listener

  private FilePickUtils.OnFileChoose onFileChoose = new FilePickUtils.OnFileChoose() {
    @Override public void onFileChoose(String fileUri, int requestCode, int size) {
     // here you will get captured or selected image<br>
    }
  };
  

3. Call below lines on onRequestPermissionsResult and onActivityResult

 @Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
  super.onRequestPermissionsResult(requestCode, permissions, grantResults);
  if (lifeCycleCallBackManager != null) {
    lifeCycleCallBackManager.onRequestPermissionsResult(requestCode, permissions, grantResults);
  }
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  super.onActivityResult(requestCode, resultCode, data);
  if (lifeCycleCallBackManager != null) {
    lifeCycleCallBackManager.onActivityResult(requestCode, resultCode, data);
  }
}

4. Open Camera picker using

  filePickUtils.requestImageCamera(CAMERA_PERMISSION, true, true); // pass false if you dont want to allow image crope

5. Open gallery picker using

 filePickUtils.requestImageGallery(STORAGE_PERMISSION_IMAGE, true, true);
// if you want to pick multiple images from gallery call below method.(Multi image picker id not supported with crop functionality)
 filePickUtils.requestImageGallery(STORAGE_PERMISSION_IMAGE, false, false,true);

6. Add below code to your manifest

<provider
       android:name="android.support.v4.content.FileProvider"
       android:authorities="add your package name"
       android:exported="false"
       android:grantUriPermissions="true">
     <meta-data
         android:name="android.support.FILE_PROVIDER_PATHS"
         android:resource="@xml/provider_paths"/>
   </provider>

Become a better Android Developer
Millions of developers are learning at MindOrks

Online Training Program

Featured Blogs

Our Team

MindOrks is Certainly one of the best online blog to stay on top of all the Android development news, coding and design patterns. Finally a blog I can count on to keep myself updated with latest and greatest things happening in Android world.

Vipul Shah
Android Developer
Microsoft

Become Pro in Android by watching videos

OUR LEARNERS WORK AT