Skip to content

Documentation (v1.x)

Bohdan Semeniuk edited this page Sep 4, 2016 · 2 revisions

v1.x API is @Deprecated but functional

Basic usage

Step 1: import Gradle dependency

repositories {
    maven { url "https://jitpack.io" }
}
    
dependencies {
    compile 'com.github.aviadmini:quickimagepick:2.0.0'
}

v2.0.0 contains fixes to old API as well, thus is best one to use

Step 2: trigger pick flow

Show gallery apps to choose picture

  • Use one of QuickImagePick.pickFromGallery(...) methods
  • Choose allowed MIME types of files that can be picked

Choose picture using Documents app

  • Use one of QuickImagePick.pickFromDocuments(...) methods
  • Note: on pre-KitKat this will show file manager apps to choose a picture
  • Choose allowed MIME types of files that can be picked

Show camera apps to take a picture

  • Use one of QuickImagePick.pickFromCamera(...) methods
  • You can change the directory where pictures are saved by calling setCameraPicsDirectory(Context pContext, String pDirPath), set to null to use default (pictures directory on external storage)
  • EXTREMELY IMPORTANT: library does not delete the images taken by camera. You must do it yourself after you're done with them to prevent using too much storage space
  • Default settings don't need WRITE_EXTERNAL_STORAGE permission. But if you want to save camera pics to a different location you might need to grant the permission
  • Library does not need CAMERA permission. However if you have it declared in your Manifest, you must grant it to use pickFromCamera(...) methods. Refer here

Use a combination of above by specifying which types to show PickSource.CAMERA, PickSource.GALLERY and/or PickSource.DOCUMENTS (refer to sample app for usage)

  • QuickImagePick.pickFromMultipleSources(...)

Step 3: Get your picture Uri

final QuickImagePick.Callback mCallback = new QuickImagePick.Callback() {

    @Override
    public void onImagePicked(@NonNull final PickSource pPickSource, final int pRequestType, @NonNull final Uri pImageUri) {

        Log.i(TAG, "Picked: " + pImageUri.toString());

        // Do something with Uri, for example load image into and ImageView
        Glide.with(getApplicationContext())
             .load(pImageUri)
             .fitCenter()
             .into(mImageView);

    }

    @Override
    public void onError(@NonNull final PickSource pPickSource, final int pRequestType, @NonNull final String pErrorString) {

        Log.e(TAG, "Err: " + pErrorString);

    }

    @Override
    public void onCancel(@NonNull final PickSource pPickSource, final int pRequestType) {

        Log.d(TAG, "Cancel: " + pPickSource.name());

    }

};

@Override
protected void onActivityResult(final int pRequestCode, final int pResultCode, final Intent pData) {
super.onActivityResult(pRequestCode, pResultCode, pData);
    super.onActivityResult(pRequestCode, pResultCode, pData);
    
    QuickImagePick.handleActivityResult(getApplicationContext(), pRequestCode, pResultCode, pData, this.mCallback);
            
}

Extras

Save content from Uri to a File

UriUtils.saveContentToFile(Context, Uri, File) throws IOException;

Allow only local content to be picked

QuickImagePick.allowOnlyLocalContent(boolean);

Set allowed MIME types of files that can be picked (gallery/documents)

QuickImagePick.setAllowedMimeTypes(Context, String...);
QuickImagePick.setAllowedMimeTypes(Context, List<String>);
QuickImagePick.setAllowedMimeTypes(Context, Set<String>);
QuickImagePick.setAllImageTypesAllowed(Context);

Get MIME type or common file extension of an Uri

UriUtils.getUriMimeType(Context, Uri);
UriUtils.getUriFileExtension(Context, Uri);

Delete content specified by Uri

UriUtils.deleteContent(Context, Uri);

Clone this wiki locally