diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c1300cae..1f5535a4 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,13 +2,21 @@ + + + + - + @@ -16,5 +24,4 @@ - diff --git a/app/src/main/java/com/simplemobiletools/camera/MainActivity.java b/app/src/main/java/com/simplemobiletools/camera/MainActivity.java index ac8f1ae3..f7af2b33 100644 --- a/app/src/main/java/com/simplemobiletools/camera/MainActivity.java +++ b/app/src/main/java/com/simplemobiletools/camera/MainActivity.java @@ -1,13 +1,49 @@ package com.simplemobiletools.camera; -import android.support.v7.app.AppCompatActivity; +import android.hardware.Camera; import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.util.Log; public class MainActivity extends AppCompatActivity { + private static final String TAG = MainActivity.class.getSimpleName(); + private Camera camera; + private boolean isOpen; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } + + @Override + protected void onResume() { + super.onResume(); + openCamera(); + } + + @Override + protected void onPause() { + super.onPause(); + releaseCamera(); + } + + private void openCamera() { + isOpen = false; + + try { + releaseCamera(); + camera = Camera.open(); + isOpen = (camera != null); + } catch (Exception e) { + Log.e(TAG, "openCamera exception " + e.getMessage()); + } + } + + private void releaseCamera() { + if (camera != null) { + camera.release(); + camera = null; + } + } }