diff --git a/app/src/main/java/com/simplemobiletools/camera/Preview.java b/app/src/main/java/com/simplemobiletools/camera/Preview.java index 8cade030..d913d858 100644 --- a/app/src/main/java/com/simplemobiletools/camera/Preview.java +++ b/app/src/main/java/com/simplemobiletools/camera/Preview.java @@ -49,7 +49,15 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O public void setCamera(int cameraId) { currCameraId = cameraId; - final Camera newCamera = Camera.open(cameraId); + Camera newCamera; + try { + newCamera = Camera.open(cameraId); + } catch (Exception e) { + Utils.showToast(getContext(), R.string.camera_open_error); + Log.e(TAG, "setCamera open " + e.getMessage()); + return; + } + if (camera == newCamera) { return; } @@ -73,7 +81,7 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O try { camera.setPreviewDisplay(surfaceHolder); } catch (IOException e) { - Log.e(TAG, "setCamera " + e.getMessage()); + Log.e(TAG, "setCamera setPreviewDisplay " + e.getMessage()); } setupPreview(); } diff --git a/app/src/main/java/com/simplemobiletools/camera/Utils.java b/app/src/main/java/com/simplemobiletools/camera/Utils.java index ed636f7b..fc415ff2 100644 --- a/app/src/main/java/com/simplemobiletools/camera/Utils.java +++ b/app/src/main/java/com/simplemobiletools/camera/Utils.java @@ -1,6 +1,8 @@ package com.simplemobiletools.camera; +import android.content.Context; import android.hardware.Camera; +import android.widget.Toast; public class Utils { public static Camera.CameraInfo getCameraInfo(int cameraId) { @@ -8,4 +10,8 @@ public class Utils { Camera.getCameraInfo(cameraId, info); return info; } + + public static void showToast(Context context, int resId) { + Toast.makeText(context, context.getResources().getString(resId), Toast.LENGTH_SHORT).show(); + } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8616cba7..68b3144a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,3 +1,4 @@ Simple Camera + An error occurred at obtaining the camera