Skip to content

Commit

Permalink
Added check for camera intent
Browse files Browse the repository at this point in the history
Fixed app crashes with ActivityNotFoundException, When camera app is disabled on the device

#69
  • Loading branch information
Dhaval2404 committed Apr 23, 2020
1 parent cec2131 commit d26715d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ class CameraProvider(activity: ImagePickerActivity) : BaseProvider(activity) {
* Start Camera Capture Intent
*/
fun startIntent() {
if (!IntentUtils.isCameraAppAvailable(this)) {
setError(R.string.error_camera_app_not_found)
return
}

checkPermission()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ object IntentUtils {
return intent
}

/**
* Check if Camera App is available or not
*
* @return true if Camera App is Available else return false
*/
fun isCameraAppAvailable(context: Context) : Boolean {
val intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
return intent.resolveActivity(context.packageManager) != null
}

fun isCameraHardwareAvailable(context: Context): Boolean {
return context.packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY)
}
Expand Down
2 changes: 2 additions & 0 deletions imagepicker/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@
<string name="error_failed_to_compress_image">Failed to compress image</string>
<string name="error_task_cancelled">Task Cancelled</string>

<string name="error_camera_app_not_found">Camera app not found</string>


</resources>

0 comments on commit d26715d

Please sign in to comment.