diff --git a/AndroidCameraServer/res/values-es/strings.xml b/AndroidCameraServer/res/values-es/strings.xml
new file mode 100644
index 0000000..0919741
--- /dev/null
+++ b/AndroidCameraServer/res/values-es/strings.xml
@@ -0,0 +1,8 @@
+
+
+
+ AndroidCameraServer
+ Configuración
+ No se pudo inicializar la cámara
+
+
diff --git a/AndroidCameraServer/res/values/strings.xml b/AndroidCameraServer/res/values/strings.xml
index 3332f5a..6c9e6b3 100644
--- a/AndroidCameraServer/res/values/strings.xml
+++ b/AndroidCameraServer/res/values/strings.xml
@@ -2,7 +2,7 @@
AndroidCameraServer
- Hello world!
Settings
+ Camera couldn\'t be initialized
\ No newline at end of file
diff --git a/AndroidCameraServer/src/com/linaresdigital/android/androidcameraserver/MainActivity.java b/AndroidCameraServer/src/com/linaresdigital/android/androidcameraserver/MainActivity.java
index bc2e690..9efd692 100644
--- a/AndroidCameraServer/src/com/linaresdigital/android/androidcameraserver/MainActivity.java
+++ b/AndroidCameraServer/src/com/linaresdigital/android/androidcameraserver/MainActivity.java
@@ -21,6 +21,7 @@
import android.util.Log;
import android.view.Menu;
import android.widget.FrameLayout;
+import android.widget.Toast;
public class MainActivity extends Activity {
@@ -52,14 +53,6 @@ protected void onCreate(Bundle savedInstanceState) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
/* Provide continuous autofocus if camera does not support it */
autoFocusHandler = new Handler();
- /* Get an instance of the default camera */
- mCamera = getCameraInstance();
- /* We create an instance of CameraPreview to manage the camera */
- mPreview = new CameraPreview(this, mCamera, previewCb, autoFocusCB);
- /* Find the frame that will contain the camera preview */
- preview = (FrameLayout) findViewById(R.id.frameLayout);
- /* Add view to frame */
- preview.addView(mPreview);
/* Initialize ICE, copied from an example */
/**************************************************************************/
@@ -104,6 +97,8 @@ private void releaseCamera() {
if (mCamera != null) {
/* Disable callbacks */
mCamera.setPreviewCallback(null);
+ mCamera.stopPreview();
+ mCamera.lock();
mCamera.release();
mCamera = null;
/* Save the state */
@@ -178,20 +173,27 @@ public void onStop() {
}
public void onPause() {
- super.onPause();
releaseCamera();
preview.removeAllViews();
mPreview = null;
+ super.onPause();
}
@Override
protected void onResume() {
super.onResume();
- /* Create a fresh instance of CameraPreview to manage the camera */
+ /* Get an instance of the default camera */
+ mCamera = getCameraInstance();
+ if (mCamera == null) {
+ Toast.makeText(getApplicationContext(), R.string.error_camera,
+ Toast.LENGTH_LONG);
+ this.finish();
+ }
+ /* We create an instance of CameraPreview to manage the camera */
mPreview = new CameraPreview(this, mCamera, previewCb, autoFocusCB);
/* Find the frame that will contain the camera preview */
preview = (FrameLayout) findViewById(R.id.frameLayout);
- /* Add new view to frame */
+ /* Add view to frame */
preview.addView(mPreview);
}