Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.nicrob64:imageselector:'
}
dependencies {
implementation("com.github.nicrob64:imageselector:")
}
<dependency>
<groupId>com.github.nicrob64</groupId>
<artifactId>imageselector</artifactId>
<version></version>
</dependency>
libraryDependencies += "com.github.nicrob64" % "imageselector" % ""
:dependencies [[com.github.nicrob64/imageselector ""]]
Image selector library for Android. Support single choice、multi-choice、cropping image and preview image.
1) Add Library module as a dependency in your build.gradle file.
or
dependencies {
compile 'com.github.Nicrob64:ImageSelector:1.0.13'
}
2) Declare permission in your AndroidManifest.xml
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
3) Call ImageSelectorActivity in your code (Manifest merger might handle that? not too sure)
ImageSelectorActivity.start(MainActivity.this, maxSelectNum, mode, isShow,isPreview,isCrop);
Which is equivalent to:
public static void start(Activity activity, int maxSelectNum, int mode, boolean isShow, boolean enablePreview, boolean enableCrop) {
Intent intent = new Intent(activity, ImageSelectorActivity.class);
intent.putExtra(EXTRA_MAX_SELECT_NUM, maxSelectNum);
intent.putExtra(EXTRA_SELECT_MODE, mode);
intent.putExtra(EXTRA_SHOW_CAMERA, isShow);
intent.putExtra(EXTRA_ENABLE_PREVIEW, enablePreview);
intent.putExtra(EXTRA_ENABLE_CROP, enableCrop);
activity.startActivityForResult(intent, REQUEST_IMAGE);
}
Other options:
//choose videos instead of images
intent.putExtra(ImageSelectorActivity.EXTRA_MEDIA_TYPE, ImageSelectorActivity.TYPE_VIDEO);
4) Receive result in your onActivityResult Method
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(resultCode == RESULT_OK && requestCode == ImageSelectorActivity.REQUEST_IMAGE){
ArrayList<String> images = (ArrayList<String>) data.getSerializableExtra(ImageSelectorActivity.REQUEST_OUTPUT);
// do something
}
}
###License
The MIT License (MIT)
Modifications Copyright (c) 2016 Nic Robertson Original library Copyright (c) 2015 Dee
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.