Select a photo activity for android by stock camera or photos
This library already included in JCenter & MavenCentral
compile 'org.ligboy.android:selectphoto:1.1.1'
-
Define String res:
@string/sp_provider_authorities
, This is the authorities of the FileProvider for capture picture. -
Define a Theme:
<style name="AppTheme.Transparent">
<item name="android:windowIsTranslucent">true</item>
</style>
- Add
SelectImageActivity
toAndroidManifest.xml
<activity android:name="org.ligboy.selectphoto.SelectImageActivity"
android:theme="@style/AppTheme.Transparent"/>
- Let's start it
SelectImageActivity.builder()
.asSquare()
.setFixAspectRatio(true)
.withMaxSize(1024, 1024)
.withCrop(true)
.start(MainActivity.this);
OnActivityResult:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == SelectImageActivity.REQUEST_CODE_SELECT_IMAGE
&& resultCode == Activity.RESULT_OK && data != null && data.getData() != null) {
Uri uri = data.getData(); //The image uri.
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}