Add front camera support for android (#876)

* Add front camera support for android

* Update readme

* Update readme
This commit is contained in:
Oleh Misuna 2018-11-09 15:04:45 +02:00 committed by Ivan Pusic
parent 6a39898355
commit de3a52c41c
2 changed files with 11 additions and 1 deletions

View File

@ -118,7 +118,7 @@ ImagePicker.clean().then(() => {
| maxFiles (ios only) | number (default 5) | Max number of files to select when using `multiple` option |
| waitAnimationEnd (ios only) | bool (default true) | Promise will resolve/reject once ViewController `completion` block is called |
| smartAlbums (ios only) | array ([supported values](https://github.com/ivpusic/react-native-image-crop-picker/blob/master/README.md#smart-album-types-ios)) (default ['UserLibrary', 'PhotoStream', 'Panoramas', 'Videos', 'Bursts']) | List of smart albums to choose from |
| useFrontCamera (ios only) | bool (default false) | Whether to default to the front/'selfie' camera when opened |
| useFrontCamera | bool (default false) | Whether to default to the front/'selfie' camera when opened |
| compressVideoPreset (ios only) | string (default MediumQuality) | Choose which preset will be used for video compression |
| compressImageMaxWidth | number (default none) | Compress image with maximum width |
| compressImageMaxHeight | number (default none) | Compress image with maximum height |
@ -326,6 +326,10 @@ android {
- [Optional] If you want to use camera picker in your project, add following to `app\src\main\AndroidManifest.xml`
- `<uses-permission android:name="android.permission.CAMERA"/>`
- [Optional] If you want to use front camera, also add following to `app\src\main\AndroidManifest.xml`
- `<uses-feature android:name="android.hardware.camera" android:required="false" />`
- `<uses-feature android:name="android.hardware.camera.front" android:required="false" />`
## Production build
### iOS

View File

@ -76,6 +76,7 @@ class PickerModule extends ReactContextBaseJavaModule implements ActivityEventLi
private boolean hideBottomControls = false;
private boolean enableRotationGesture = false;
private boolean disableCropperColorSetters = false;
private boolean useFrontCamera = false;
private ReadableMap options;
//Grey 800
@ -132,6 +133,7 @@ class PickerModule extends ReactContextBaseJavaModule implements ActivityEventLi
hideBottomControls = options.hasKey("hideBottomControls") ? options.getBoolean("hideBottomControls") : false;
enableRotationGesture = options.hasKey("enableRotationGesture") ? options.getBoolean("enableRotationGesture") : false;
disableCropperColorSetters = options.hasKey("disableCropperColorSetters") ? options.getBoolean("disableCropperColorSetters") : false;
useFrontCamera = options.hasKey("useFrontCamera") ? options.getBoolean("useFrontCamera") : false;
this.options = options;
}
@ -305,6 +307,10 @@ class PickerModule extends ReactContextBaseJavaModule implements ActivityEventLi
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCameraCaptureURI);
if (this.useFrontCamera) {
cameraIntent.putExtra("android.intent.extras.CAMERA_FACING", 1);
}
if (cameraIntent.resolveActivity(activity.getPackageManager()) == null) {
resultCollector.notifyProblem(E_CANNOT_LAUNCH_CAMERA, "Cannot launch camera");
return;