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 Dec 18, 2020
1 parent 9e0054d commit 6df15ed
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
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 @@ -80,4 +80,15 @@ object IntentUtils {
fun isCameraHardwareAvailable(context: Context): Boolean {
return context.packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY)
}

/**
* 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
}

}
1 change: 1 addition & 0 deletions imagepicker/src/main/res/values-pl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<string name="error_failed_to_crop_image">Nie udało się zmienić rozmiarów obrazu</string>
<string name="error_failed_to_compress_image">Podczas kompresji obrazu wystąpił błąd</string>
<string name="error_task_cancelled">Zadanie przerwane</string>
<string name="error_camera_app_not_found">Nie znaleziono aplikacji aparatu</string>
<!-- ImagePicker string resource end -->

<!-- uCrop string resource start -->
Expand Down
2 changes: 1 addition & 1 deletion imagepicker/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
<string name="error_failed_to_crop_image">Failed to crop image</string>
<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 6df15ed

Please sign in to comment.