Skip to content

Commit

Permalink
Fixed ImagePicker crash while capturing Camera Image and Camera Permi…
Browse files Browse the repository at this point in the history
…ssion is Defined in Manifest

Fixed ImagePicker crash while capturing Camera Image and Camera Permission is Defined in Manifest

#34
  • Loading branch information
Dhaval2404 committed Sep 30, 2019
1 parent d04132b commit aa82942
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ class CameraProvider(activity: ImagePickerActivity) : BaseProvider(activity) {
Manifest.permission.WRITE_EXTERNAL_STORAGE
)

/**
* Permission Require for Image Capture using Camera
*/
private val REQUIRED_PERMISSIONS_EXTENDED = arrayOf(
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.CAMERA
)

private const val CAMERA_INTENT_REQ_CODE = 4281
private const val PERMISSION_INTENT_REQ_CODE = 4282
}
Expand All @@ -52,7 +60,14 @@ class CameraProvider(activity: ImagePickerActivity) : BaseProvider(activity) {
* If permission is not granted request Permission, Else start Camera Intent
*/
private fun checkPermission() {
if (!PermissionUtil.isPermissionGranted(this, REQUIRED_PERMISSIONS)) {
//Check if Camera permission defined in manifest
val requireCameraPermission = PermissionUtil.isPermissionInManifest(this, Manifest.permission.CAMERA)
if (requireCameraPermission && !isPermissionGranted(this, REQUIRED_PERMISSIONS_EXTENDED)) {
//If Camera permission defined in AndroidManifest then Need to request Camera Permission
//Ref: https://github.com/Dhaval2404/ImagePicker/issues/34
requestPermissions(activity, REQUIRED_PERMISSIONS_EXTENDED, PERMISSION_INTENT_REQ_CODE)
} else if (!isPermissionGranted(this, REQUIRED_PERMISSIONS)) {
//If Camera permission is not defined in AndroidManifest then no need to request Camera Permission
requestPermissions(activity, REQUIRED_PERMISSIONS, PERMISSION_INTENT_REQ_CODE)
} else {
startCameraIntent()
Expand Down

0 comments on commit aa82942

Please sign in to comment.