Add cameraRequestPermissions XML attribute

pull/718/head
Mattia Iavarone 6 years ago
parent 9528df6c2c
commit c49348801e
  1. 1
      README.md
  2. 11
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java
  3. 3
      cameraview/src/main/res/values/attrs.xml
  4. 11
      docs/_posts/2018-12-20-runtime-permissions.md

@ -148,6 +148,7 @@ Using CameraView is extremely simple:
app:cameraPictureMetering="true|false"
app:cameraPictureSnapshotMetering="false|true"
app:cameraPictureFormat="jpeg|dng"
app:cameraRequestPermissions="true|false"
app:cameraExperimental="false|true">
<!-- Watermark! -->

@ -116,12 +116,14 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
final static boolean DEFAULT_USE_DEVICE_ORIENTATION = true;
final static boolean DEFAULT_PICTURE_METERING = true;
final static boolean DEFAULT_PICTURE_SNAPSHOT_METERING = false;
final static boolean DEFAULT_REQUEST_PERMISSIONS = true;
final static int DEFAULT_FRAME_PROCESSING_POOL_SIZE = 2;
final static int DEFAULT_FRAME_PROCESSING_EXECUTORS = 1;
// Self managed parameters
private boolean mPlaySounds;
private boolean mUseDeviceOrientation;
private boolean mRequestPermissions;
private HashMap<Gesture, GestureAction> mGestureMap = new HashMap<>(4);
private Preview mPreview;
private Engine mEngine;
@ -186,6 +188,8 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
boolean useDeviceOrientation = a.getBoolean(
R.styleable.CameraView_cameraUseDeviceOrientation, DEFAULT_USE_DEVICE_ORIENTATION);
mExperimental = a.getBoolean(R.styleable.CameraView_cameraExperimental, false);
mRequestPermissions = a.getBoolean(R.styleable.CameraView_cameraRequestPermissions,
DEFAULT_REQUEST_PERMISSIONS);
mPreview = controls.getPreview();
mEngine = controls.getEngine();
@ -779,11 +783,14 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
needsAudio = needsAudio && c.checkSelfPermission(Manifest.permission.RECORD_AUDIO)
!= PackageManager.PERMISSION_GRANTED;
if (needsCamera || needsAudio) {
if (!needsCamera && !needsAudio) {
return true;
} else if (mRequestPermissions) {
requestPermissions(needsCamera, needsAudio);
return false;
} else {
return false;
}
return true;
}
/**

@ -156,7 +156,8 @@
<enum name="dng" value="1" />
</attr>
<attr name="cameraExperimental" format="boolean" />
<attr name="cameraRequestPermissions" format="boolean|reference"/>
<attr name="cameraExperimental" format="boolean|reference" />
</declare-styleable>

@ -39,11 +39,14 @@ device has cameras, and then start the camera view.
### Handling
On Marshmallow+, the user must explicitly approve our permissions. You can
On Marshmallow+, the user must explicitly approve our permissions. You can either:
- handle permissions yourself and then call `open()` or `setLifecycleOwner()` once they are acquired
- ignore this: `CameraView` will present a permission request to the user based on
- let `CameraView` request permissions: we will present a permission request to the user based on
whether they are needed or not with the current configuration.
Note however, that this is done at the activity level, so the permission request callback
`onRequestPermissionResults()` will be invoked on the parent activity, not the fragment.
The automatic request is currently done at the activity level, so the permission request callback
`onRequestPermissionResults()` will be invoked on the parent activity, not the fragment.
The automatic request can be disabled by setting `app:cameraRequestPermissions="false"` in your
XML declaration.
Loading…
Cancel
Save