Simpllify camera handling
package de.stephanlindauer.criticalmaps.handler;
-import android.annotation.SuppressLint;
+import android.content.ActivityNotFoundException;
import android.content.ClipData;
import android.content.Intent;
-import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.provider.MediaStore;
@@ -26,29 +25,7 @@ public class StartCameraHandler {
this.activity = mainActivity;
}
- @SuppressLint("UnsupportedChromeOsCameraSystemFeature")
public void execute() {
- boolean deviceHasCamera;
- if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN) {
- deviceHasCamera =
- activity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA);
- } else {
- deviceHasCamera =
- activity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY);
- }
-
- if (!deviceHasCamera) {
- AlertBuilder.show(activity, R.string.something_went_wrong, R.string.camera_no_camera);
- return;
- }
-
- Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
- if (cameraIntent.resolveActivity(activity.getPackageManager()) == null) {
- // TODO: 03.02.2018 more specific msg indicating there's no app to handle this intent
- AlertBuilder.show(activity, R.string.something_went_wrong, R.string.camera_no_camera);
- return;
- }
-
if (App.components().ownLocationmodel().ownLocation == null) {
AlertBuilder.show(activity, R.string.something_went_wrong, R.string.camera_no_location);
return;
@@ -66,6 +43,7 @@ public class StartCameraHandler {
activity.getResources().getString(R.string.fileprovider_authority),
outputFile);
+ Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
// Workaround for permission issue on older devices, see:
// https://medium.com/@quiro91/sharing-files-through-intents-part-2-fixing-the-permissions-before-lollipop-ceb9bb0eec3a
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP) {
@@ -75,7 +53,12 @@ public class StartCameraHandler {
}
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageCaptureUri);
+
+ try {
activity.startActivityForResult(
cameraIntent, RequestCodes.CAMERA_CAPTURE_IMAGE_REQUEST_CODE);
+ } catch (ActivityNotFoundException e) {
+ AlertBuilder.show(activity, R.string.something_went_wrong, R.string.camera_no_camera);
+ }
}
}
