{"id":15199,"date":"2014-10-10T12:10:05","date_gmt":"2014-10-10T09:10:05","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=15199"},"modified":"2019-04-24T15:59:47","modified_gmt":"2019-04-24T12:59:47","slug":"android-camera-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/android\/core\/hardware\/camera-hardware\/android-camera-example\/","title":{"rendered":"Android Camera Example"},"content":{"rendered":"<p>In our previous Android Example, we tried to explain the use of <a href=\"http:\/\/examples.javacodegeeks.com\/android\/core\/ui\/android-surfaceview-example\/\"><code>Android SurfaceView<\/code><\/a> through a simple camera application. In the meantime, we realized how important is the &#8220;camera mode&#8221; in a simple and modern Android application, as nowadays it is becoming very common, that the camera is used not only to capture basic portraits and landscape views, but also to be used for other reasons, for instance to capture the number of a credit card in a commercial application, even to be able to save a title and a name, or even to read a qr code.<\/p>\n<p>The Android framework includes support for various cameras and camera features available on devices, allowing you to capture pictures and videos in your applications.<\/p>\n<p>So, in this example, we are going to see the use of <a href=\"http:\/\/developer.android.com\/reference\/android\/hardware\/Camera.html\"><code>Android Camera<\/code><\/a> api in a more detailed way, and develop an Android application that takes photos and switches between the front and the back camera of our mobile device.<\/p>\n<p>For our example will use the following tools in a Windows 64-bit or an  OS X platform:<\/p>\n<ul>\n<li>JDK 1.7<\/li>\n<li>Eclipse 4.2 Juno<\/li>\n<li>Android SDK 4.4.2<\/li>\n<\/ul>\n<p>Let\u2019s take a closer look:\n<\/p>\n<h2>1. Create a New Android Application Project<\/h2>\n<div class=\"tip\"><strong>Tip<\/strong><br \/>\nYou may skip project creation and jump directly to the <a href=\"#code\"><strong>beginning of the example<\/strong><\/a> below.<\/div>\n<p>Open Eclipse IDE and go to File \u2192 New \u2192 Project \u2192 Android Application Project.<\/p>\n<p><figure id=\"attachment_13637\" aria-describedby=\"caption-attachment-13637\" style=\"width: 596px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/AndroidExample1.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/AndroidExample1.png\" alt=\"Figure 2. Create a new Android project\" width=\"596\" height=\"559\" class=\"size-full wp-image-13637\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/AndroidExample1.png 596w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/AndroidExample1-300x281.png 300w\" sizes=\"(max-width: 596px) 100vw, 596px\" \/><\/a><figcaption id=\"caption-attachment-13637\" class=\"wp-caption-text\">Figure 1. Create a new Android project<\/figcaption><\/figure><\/p>\n<p>Specify the name of the application, the project and the package and then click Next.<\/p>\n<p><figure id=\"attachment_13786\" aria-describedby=\"caption-attachment-13786\" style=\"width: 636px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/AndroidCameraExample-1.jpg\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/AndroidCameraExample-1.jpg\" alt=\"Figure 2. Create a new Android project name\" width=\"636\" height=\"543\" class=\"size-full wp-image-13786\"><\/a><figcaption id=\"caption-attachment-13786\" class=\"wp-caption-text\">Figure 2. Create a new Android project name<\/figcaption><\/figure><\/p>\n<p>In the next window, the \u201cCreate Activity\u201d option should be checked. The new created activity will be the main activity of your project. Then press Next button.<\/p>\n<p><figure id=\"attachment_11777\" aria-describedby=\"caption-attachment-11777\" style=\"width: 636px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/AndroidCameraExample-2.jpg\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/AndroidCameraExample-2.jpg\" alt=\"Create Activity\" width=\"636\" height=\"543\" class=\"alignnone size-full wp-image-13642\"><\/a><figcaption id=\"caption-attachment-11777\" class=\"wp-caption-text\">Figure 3. Configure the project<\/figcaption><\/figure><\/p>\n<p>In \u201cConfigure Launcher Icon\u201d window you should choose the icon you want to have in your app. We will use the default icon of android, so click Next.<\/p>\n<p><figure id=\"attachment_11778\" aria-describedby=\"caption-attachment-11778\" style=\"width: 660px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/AndroidExample4.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/AndroidExample4.png\" alt=\"Configure Launcher Icon\" width=\"660\" height=\"590\" class=\"alignnone size-full wp-image-13638\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/AndroidExample4.png 660w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/AndroidExample4-300x268.png 300w\" sizes=\"(max-width: 660px) 100vw, 660px\" \/><\/a><figcaption id=\"caption-attachment-11778\" class=\"wp-caption-text\">Figure 4. Configure the launcher icon<\/figcaption><\/figure><\/p>\n<p>Select the \u201cBlank Activity\u201d option and press Next.<\/p>\n<p><figure id=\"attachment_11779\" aria-describedby=\"caption-attachment-11779\" style=\"width: 660px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/AndroidExample5.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/AndroidExample5.png\" alt=\"Blank Activity\" width=\"660\" height=\"590\" class=\"alignnone size-full wp-image-13639\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/AndroidExample5.png 660w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/AndroidExample5-300x268.png 300w\" sizes=\"(max-width: 660px) 100vw, 660px\" \/><\/a><figcaption id=\"caption-attachment-11779\" class=\"wp-caption-text\">Figure 5. Create the activity and select its type<\/figcaption><\/figure><\/p>\n<p>You have to specify a name for the new Activity and a name for the layout description of your app. The .xml file for the layout will automatically be created in the res\/layout folder. It will also be created a fragment layout xml, that we are not going to use in this project and you can remove it if you want. Then press Finish.<\/p>\n<p><figure id=\"attachment_13788\" aria-describedby=\"caption-attachment-13788\" style=\"width: 660px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/AndroidCameraExample-3.jpg\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/AndroidCameraExample-3.jpg\" alt=\"Figure 6. Create a new blank activity\" width=\"660\" height=\"590\" class=\"size-full wp-image-13788\"><\/a><figcaption id=\"caption-attachment-13788\" class=\"wp-caption-text\">Figure 6. Create a new blank activity<\/figcaption><\/figure><\/p>\n<p>Here you can see, how will the structure of the project become when finished:<\/p>\n<p><figure id=\"attachment_13789\" aria-describedby=\"caption-attachment-13789\" style=\"width: 366px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/AndroidCameraExample-4.jpg\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/AndroidCameraExample-4.jpg\" alt=\"Figure 7. The tree of the project\" width=\"366\" height=\"507\" class=\"size-full wp-image-13789\"><\/a><figcaption id=\"caption-attachment-13789\" class=\"wp-caption-text\">Figure 7. The tree of the project<\/figcaption><\/figure><\/p>\n<p><span id=\"code\"> <\/span><\/p>\n<h2>2. Creating the layout of the main AndroidCameraExample<\/h2>\n<p>We are going to make a simple layout xml for the <code>AndroidCameraExample.class<\/code>, that consists of a <code>LinearLayout<\/code> with horizontal orientation, that includes the <code>SurfaceView<\/code> for the camera preview view on the left, and two buttons on the right. Let&#8217;s see this in detail.<\/p>\n<p>Open <code>res\/layout\/activity_main.xml<\/code>, go to the respective xml tab and paste the following:<\/p>\n<p><em><span style=\"text-decoration: underline\">activity_main.xml<\/span><\/em><\/p>\n<pre class=\"brush:xml; wrap-lines:false;\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n&lt;LinearLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    android:layout_width=\"fill_parent\"\n    android:layout_height=\"fill_parent\"\n    android:orientation=\"horizontal\" &gt;\n\n    &lt;LinearLayout\n        android:id=\"@+id\/camera_preview\"\n        android:layout_width=\"fill_parent\"\n        android:layout_height=\"fill_parent\"\n        android:layout_weight=\"1\" \n        android:orientation=\"horizontal\"\/&gt;\n\n    &lt;LinearLayout\n        android:id=\"@+id\/buttonsLayout\"\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"match_parent\"\n        android:layout_gravity=\"center\"\n        android:orientation=\"vertical\" &gt;\n        &lt;Button\n            android:id=\"@+id\/button_ChangeCamera\"\n            android:layout_width=\"72dp\"\n            android:layout_height=\"wrap_content\"\n            android:text=\"Switch Camera\" \n            android:layout_marginTop=\"30dp\"\/&gt;\n        &lt;Button\n            android:id=\"@+id\/button_capture\"\n            android:layout_width=\"wrap_content\"\n            android:layout_height=\"wrap_content\"\n            android:text=\"Capture\" \n            android:layout_marginTop=\"100dp\"\/&gt;\n    &lt;\/LinearLayout&gt;\n&lt;\/LinearLayout&gt;\n<\/pre>\n<h2>3. Creating the source code of the main AndroidCameraExample Activity<\/h2>\n<p>As you have noticed, for the purpose of this example, we are going to have an Activity with a customized <code>SurfaceView<\/code> class for this Activity.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>Open <code>src\/com.javacodegeeks.androidcameraexample\/AndroidCameraExample.java<\/code> file and paste the code below.<\/p>\n<p><em><span style=\"text-decoration: underline\">AndroidCameraExample.java<\/span><\/em><\/p>\n<pre class=\"brush:java; wrap-lines:false\">package com.javacodegeeks.androidcameraexample;\n\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.FileOutputStream;\nimport java.io.IOException;\nimport java.text.SimpleDateFormat;\nimport java.util.Date;\n\nimport android.app.Activity;\nimport android.content.Context;\nimport android.content.pm.PackageManager;\nimport android.hardware.Camera;\nimport android.hardware.Camera.CameraInfo;\nimport android.hardware.Camera.PictureCallback;\nimport android.os.Bundle;\nimport android.view.View;\nimport android.view.View.OnClickListener;\nimport android.view.WindowManager;\nimport android.widget.Button;\nimport android.widget.LinearLayout;\nimport android.widget.Toast;\n\npublic class AndroidCameraExample extends Activity {\n\tprivate Camera mCamera;\n\tprivate CameraPreview mPreview;\n\tprivate PictureCallback mPicture;\n\tprivate Button capture, switchCamera;\n\tprivate Context myContext;\n\tprivate LinearLayout cameraPreview;\n\tprivate boolean cameraFront = false;\n\n\t@Override\n\tpublic void onCreate(Bundle savedInstanceState) {\n\t\tsuper.onCreate(savedInstanceState);\n\t\tsetContentView(R.layout.activity_main);\n\t\tgetWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);\n\t\tmyContext = this;\n\t\tinitialize();\n\t}\n\n\tprivate int findFrontFacingCamera() {\n\t\tint cameraId = -1;\n\t\t\/\/ Search for the front facing camera\n\t\tint numberOfCameras = Camera.getNumberOfCameras();\n\t\tfor (int i = 0; i &lt; numberOfCameras; i++) {\n\t\t\tCameraInfo info = new CameraInfo();\n\t\t\tCamera.getCameraInfo(i, info);\n\t\t\tif (info.facing == CameraInfo.CAMERA_FACING_FRONT) {\n\t\t\t\tcameraId = i;\n\t\t\t\tcameraFront = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\treturn cameraId;\n\t}\n\n\tprivate int findBackFacingCamera() {\n\t\tint cameraId = -1;\n\t\t\/\/Search for the back facing camera\n\t\t\/\/get the number of cameras\n\t\tint numberOfCameras = Camera.getNumberOfCameras();\n\t\t\/\/for every camera check\n\t\tfor (int i = 0; i &lt; numberOfCameras; i++) {\n\t\t\tCameraInfo info = new CameraInfo();\n\t\t\tCamera.getCameraInfo(i, info);\n\t\t\tif (info.facing == CameraInfo.CAMERA_FACING_BACK) {\n\t\t\t\tcameraId = i;\n\t\t\t\tcameraFront = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\treturn cameraId;\n\t}\n\n\tpublic void onResume() {\n\t\tsuper.onResume();\n\t\tif (!hasCamera(myContext)) {\n\t\t\tToast toast = Toast.makeText(myContext, \"Sorry, your phone does not have a camera!\", Toast.LENGTH_LONG);\n\t\t\ttoast.show();\n\t\t\tfinish();\n\t\t}\n\t\tif (mCamera == null) {\n\t\t\t\/\/if the front facing camera does not exist\n\t\t\tif (findFrontFacingCamera()  1) {\n\t\t\t\t\/\/release the old camera instance\n\t\t\t\t\/\/switch camera, from the front and the back and vice versa\n\t\t\t\t\n\t\t\t\treleaseCamera();\n\t\t\t\tchooseCamera();\n\t\t\t} else {\n\t\t\t\tToast toast = Toast.makeText(myContext, \"Sorry, your phone has only one camera!\", Toast.LENGTH_LONG);\n\t\t\t\ttoast.show();\n\t\t\t}\n\t\t}\n\t};\n\n\tpublic void chooseCamera() {\n\t\t\/\/if the camera preview is the front\n\t\tif (cameraFront) {\n\t\t\tint cameraId = findBackFacingCamera();\n\t\t\tif (cameraId &gt;= 0) {\n\t\t\t\t\/\/open the backFacingCamera\n\t\t\t\t\/\/set a picture callback\n\t\t\t\t\/\/refresh the preview\n\t\t\t\t\n\t\t\t\tmCamera = Camera.open(cameraId);\t\t\t\t\n\t\t\t\tmPicture = getPictureCallback();\t\t\t\n\t\t\t\tmPreview.refreshCamera(mCamera);\n\t\t\t}\n\t\t} else {\n\t\t\tint cameraId = findFrontFacingCamera();\n\t\t\tif (cameraId &gt;= 0) {\n\t\t\t\t\/\/open the backFacingCamera\n\t\t\t\t\/\/set a picture callback\n\t\t\t\t\/\/refresh the preview\n\t\t\t\t\n\t\t\t\tmCamera = Camera.open(cameraId);\n\t\t\t\tmPicture = getPictureCallback();\n\t\t\t\tmPreview.refreshCamera(mCamera);\n\t\t\t}\n\t\t}\n\t}\n\n\t@Override\n\tprotected void onPause() {\n\t\tsuper.onPause();\n\t\t\/\/when on Pause, release camera in order to be used from other applications\n\t\treleaseCamera();\n\t}\n\n\tprivate boolean hasCamera(Context context) {\n\t\t\/\/check if the device has camera\n\t\tif (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)) {\n\t\t\treturn true;\n\t\t} else {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tprivate PictureCallback getPictureCallback() {\n\t\tPictureCallback picture = new PictureCallback() {\n\n\t\t\t@Override\n\t\t\tpublic void onPictureTaken(byte[] data, Camera camera) {\n\t\t\t\t\/\/make a new picture file\n\t\t\t\tFile pictureFile = getOutputMediaFile();\n\t\t\t\t\n\t\t\t\tif (pictureFile == null) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\t\/\/write the file\n\t\t\t\t\tFileOutputStream fos = new FileOutputStream(pictureFile);\n\t\t\t\t\tfos.write(data);\n\t\t\t\t\tfos.close();\n\t\t\t\t\tToast toast = Toast.makeText(myContext, \"Picture saved: \" + pictureFile.getName(), Toast.LENGTH_LONG);\n\t\t\t\t\ttoast.show();\n\n\t\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t\/\/refresh camera to continue preview\n\t\t\t\tmPreview.refreshCamera(mCamera);\n\t\t\t}\n\t\t};\n\t\treturn picture;\n\t}\n\n\tOnClickListener captrureListener = new OnClickListener() {\n\t\t@Override\n\t\tpublic void onClick(View v) {\n\t\t\tmCamera.takePicture(null, null, mPicture);\n\t\t}\n\t};\n\n\t\/\/make picture and save to a folder\n\tprivate static File getOutputMediaFile() {\n\t\t\/\/make a new file directory inside the \"sdcard\" folder\n\t\tFile mediaStorageDir = new File(\"\/sdcard\/\", \"JCG Camera\");\n\t\t\n\t\t\/\/if this \"JCGCamera folder does not exist\n\t\tif (!mediaStorageDir.exists()) {\n\t\t\t\/\/if you cannot make this folder return\n\t\t\tif (!mediaStorageDir.mkdirs()) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\t\n\t\t\/\/take the current timeStamp\n\t\tString timeStamp = new SimpleDateFormat(\"yyyyMMdd_HHmmss\").format(new Date());\n\t\tFile mediaFile;\n\t\t\/\/and make a media file:\n\t\tmediaFile = new File(mediaStorageDir.getPath() + File.separator + \"IMG_\" + timeStamp + \".jpg\");\n\t\t\n\t\treturn mediaFile;\n\t}\n\n\tprivate void releaseCamera() {\n\t\t\/\/ stop and release camera\n\t\tif (mCamera != null) {\n\t\t\tmCamera.release();\n\t\t\tmCamera = null;\n\t\t}\n\t}\n}\n<\/pre>\n<p>Let&#8217;s see in detail the code above.<\/p>\n<p>We set the <code>activity_main.xml<\/code> layout and we initialize our main layout by:<\/p>\n<pre class=\"brush:java; wrap-lines:false\">setContentView(R.layout.activity_main);<\/pre>\n<p>We also set the <code>onCreate<\/code> method of the Activity:<\/p>\n<pre class=\"brush:java; wrap-lines:false\">\t@Override\n\tpublic void onCreate(Bundle savedInstanceState) {\n\t\tsuper.onCreate(savedInstanceState);\n\t\tsetContentView(R.layout.activity_main);\n\t\tgetWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);\n\t\tmyContext = this;\n\t\tinitialize();\n\t}\n<\/pre>\n<p>And the <code>onResume<\/code> method of the Activity:<\/p>\n<pre class=\"brush:java; wrap-lines:false\">\tpublic void onResume() {\n\t\tsuper.onResume();\n\t\tif (!hasCamera(myContext)) {\n\t\t\tToast toast = Toast.makeText(myContext, \"Sorry, your phone does not have a camera!\", Toast.LENGTH_LONG);\n\t\t\ttoast.show();\n\t\t\tfinish();\n\t\t}\n\t\tif (mCamera == null) {\t\t\t\n\t\t\tif (findFrontFacingCamera() &lt; 0) {\n\t\t\t\tToast.makeText(this, \"No front facing camera found.\", Toast.LENGTH_LONG).show();\n\t\t\t\tswitchCamera.setVisibility(View.GONE);\n\t\t\t}\t\t\t\n\t\t\tmCamera = Camera.open(findBackFacingCamera());\n\t\t\tmPicture = getPictureCallback();\n\t\t\tmPreview.refreshCamera(mCamera);\n\t\t}\n\t}\n<\/pre>\n<p>In the <code>onResume<\/code> method we check if the device has a hardware camera. We also check if the device has a front facing camera by executing the <code>findFrontFacingCamera()<\/code> method, which returns an integer as the id of the camera in use. If there is no second camera on the device, the switch button goes invisible.[ulp id=&#8217;Ja8Orb5oPKdShcXt&#8217;]<\/p>\n<pre class=\"brush:java; wrap-lines:false\">\tprivate int findFrontFacingCamera() {\n\t\tint cameraId = -1;\n\t\t\/\/ Search for the front facing camera\n\t\tint numberOfCameras = Camera.getNumberOfCameras();\n\t\tfor (int i = 0; i &lt; numberOfCameras; i++) {\n\t\t\tCameraInfo info = new CameraInfo();\n\t\t\tCamera.getCameraInfo(i, info);\n\t\t\tif (info.facing == CameraInfo.CAMERA_FACING_FRONT) {\n\t\t\t\tcameraId = i;\n\t\t\t\tcameraFront = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\treturn cameraId;\n\t}\n<\/pre>\n<p>Generally, when we want to initialize, or to refresh a camera instance, we use the sequence of methods:<\/p>\n<pre class=\"brush:java; wrap-lines:false\">\t\tmCamera = Camera.open(findBackFacingCamera());\n\t\tmPicture = getPictureCallback();\n\t\tmPreview.refreshCamera(mCamera);\n<\/pre>\n<p>With these methods, we set a new camera instance, by opening a camera with an id parameter, either the back facing camera, or the front facing camera. Then we set a picture callback method, and we also set the preview Surfaceview layer of the camera instance.<\/p>\n<h2>4. Creating the source code of the class CameraPreview<\/h2>\n<p>Open <code>src\/com.javacodegeeks.androidcameraexample\/CameraPreview.java<\/code> file and paste the code below.<\/p>\n<p><em><span style=\"text-decoration: underline\">CameraPreview.java<\/span><\/em><\/p>\n<pre class=\"brush:java; wrap-lines:false\">package com.javacodegeeks.androidcameraexample;\n\nimport java.io.IOException;\n\nimport android.content.Context;\nimport android.hardware.Camera;\nimport android.util.Log;\nimport android.view.SurfaceHolder;\nimport android.view.SurfaceView;\n\npublic class CameraPreview extends SurfaceView implements SurfaceHolder.Callback {\n\tprivate SurfaceHolder mHolder;\n\tprivate Camera mCamera;\n\n\tpublic CameraPreview(Context context, Camera camera) {\n\t\tsuper(context);\n\t\tmCamera = camera;\n\t\tmHolder = getHolder();\n\t\tmHolder.addCallback(this);\n\t\t\/\/ deprecated setting, but required on Android versions prior to 3.0\n\t\tmHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);\n\t}\n\n\tpublic void surfaceCreated(SurfaceHolder holder) {\n\t\ttry {\n\t\t\t\/\/ create the surface and start camera preview\n\t\t\tif (mCamera == null) {\n\t\t\t\tmCamera.setPreviewDisplay(holder);\n\t\t\t\tmCamera.startPreview();\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t\tLog.d(VIEW_LOG_TAG, \"Error setting camera preview: \" + e.getMessage());\n\t\t}\n\t}\n\n\tpublic void refreshCamera(Camera camera) {\n\t\tif (mHolder.getSurface() == null) {\n\t\t\t\/\/ preview surface does not exist\n\t\t\treturn;\n\t\t}\n\t\t\/\/ stop preview before making changes\n\t\ttry {\n\t\t\tmCamera.stopPreview();\n\t\t} catch (Exception e) {\n\t\t\t\/\/ ignore: tried to stop a non-existent preview\n\t\t}\n\t\t\/\/ set preview size and make any resize, rotate or\n\t\t\/\/ reformatting changes here\n\t\t\/\/ start preview with new settings\n\t\tsetCamera(camera);\n\t\ttry {\n\t\t\tmCamera.setPreviewDisplay(mHolder);\n\t\t\tmCamera.startPreview();\n\t\t} catch (Exception e) {\n\t\t\tLog.d(VIEW_LOG_TAG, \"Error starting camera preview: \" + e.getMessage());\n\t\t}\n\t}\n\n\tpublic void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {\n\t\t\/\/ If your preview can change or rotate, take care of those events here.\n\t\t\/\/ Make sure to stop the preview before resizing or reformatting it.\n\t\trefreshCamera(mCamera);\n\t}\n\n\tpublic void setCamera(Camera camera) {\n\t\t\/\/method to set a camera instance\n\t\tmCamera = camera;\n\t}\n\n\t@Override\n\tpublic void surfaceDestroyed(SurfaceHolder holder) {\n\t\t\/\/ TODO Auto-generated method stub\n\t\t\/\/ mCamera.release();\n\n\t}\n}\n<\/pre>\n<p>Let&#8217;s see in detail the code above.<\/p>\n<p>Most of the methods that are used here were explained in the last Android Example, the <a href=\"http:\/\/examples.javacodegeeks.com\/android\/core\/ui\/android-surfaceview-example\/\"><code>Android SurfaceView Example<\/code><\/a>. However, we will explain them once again, for the use of this example.<\/p>\n<p>In the code snippet that follows, we initialize the surface view that is created. We set a preview display of a camera instance. This means that our surface view will display the &#8220;camera sees&#8221;.<\/p>\n<pre class=\"brush:java; wrap-lines:false\">\tpublic void surfaceCreated(SurfaceHolder holder) {\n\t\ttry {\n\t\t\tif (mCamera == null) {\n\t\t\t\tmCamera.setPreviewDisplay(holder);\n\t\t\t\tmCamera.startPreview();\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t\tLog.d(VIEW_LOG_TAG, \"Error setting camera preview: \" + e.getMessage());\n\t\t}\n\t}\n<\/pre>\n<p>When the layout of our activity changes, so does the surfaceView. The <code>surfaceChanged<\/code> method is called when we resume the Activity (restore it from the background for example). When this happens, we &#8220;refresh&#8221; the preview view of the camera.<\/p>\n<pre class=\"brush:java; wrap-lines:false\">\tpublic void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {\n\t\t\/\/ If your preview can change or rotate, take care of those events here.\n\t\t\/\/ Make sure to stop the preview before resizing or reformatting it.\n\t\trefreshCamera(mCamera);\n\t}\n<\/pre>\n<p>We &#8220;refresh&#8221; the preview view with the following code. At first, we stop the preview of the old camera instance, we make any resize, rotate or reformatting changes we might want, and then we set the new camera instance, and we start the preview.<\/p>\n<pre class=\"brush:java; wrap-lines:false\">\tpublic void refreshCamera(Camera camera) {\n\t\tif (mHolder.getSurface() == null) {\n\t\t\t\/\/ preview surface does not exist\n\t\t\treturn;\n\t\t}\n\t\ttry {\n\t\t\tmCamera.stopPreview();\n\t\t} catch (Exception e) {\n\t\t\t\/\/ ignore: tried to stop a non-existent preview\n\t\t}\n\t\t\n\t\tsetCamera(camera);\n\t\ttry {\n\t\t\tmCamera.setPreviewDisplay(mHolder);\n\t\t\tmCamera.startPreview();\n\t\t} catch (Exception e) {\n\t\t\tLog.d(VIEW_LOG_TAG, \"Error starting camera preview: \" + e.getMessage());\n\t\t}\n\t}\n<\/pre>\n<h2>5. Android Manifest<\/h2>\n<p>Because this application uses the hardware camera, the front camera (if exists) and tries to save images to the device&#8217;s external storage (SD Card), we must also specify this in the manifest. The AndroidManifest.xml of our project is simple and contains the permissions:<\/p>\n<p><em><span style=\"text-decoration: underline\">AndroidManifest.xml<\/span><\/em><\/p>\n<pre class=\"brush:xml; wrap-lines:false,highlight:[11,12,13,14,15]\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n&lt;manifest xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    package=\"com.javacodegeeks.androidcameraexample\"\n    android:versionCode=\"1\"\n    android:versionName=\"1.1\" &gt;\n\n    &lt;uses-sdk\n        android:minSdkVersion=\"10\"\n        android:targetSdkVersion=\"19\" \/&gt;\n\n    &lt;uses-permission android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\" \/&gt;\n    &lt;uses-permission android:name=\"android.permission.CAMERA\" \/&gt;\n    &lt;uses-feature android:name=\"android.hardware.camera\" \/&gt;\n    &lt;uses-feature android:name=\"android.hardware.camera.autofocus\" \/&gt;\n    &lt;uses-feature android:name=\"android.hardware.camera.front\" android:required=\"false\" \/&gt;\n\n    &lt;application\n        android:icon=\"@drawable\/ic_launcher\"\n        android:label=\"@string\/app_name\" &gt;\n        &lt;activity\n            android:name=\".AndroidCameraExample\"\n            android:label=\"@string\/app_name\"\n            android:screenOrientation=\"landscape\"\n            android:theme=\"@android:style\/Theme.NoTitleBar.Fullscreen\" &gt;\n            &lt;intent-filter&gt;\n                &lt;action android:name=\"android.intent.action.MAIN\" \/&gt;\n                &lt;category android:name=\"android.intent.category.LAUNCHER\" \/&gt;\n            &lt;\/intent-filter&gt;\n        &lt;\/activity&gt;\n    &lt;\/application&gt;\n&lt;\/manifest&gt;\n<\/pre>\n<div class=\"tip\"><strong>Tip<\/strong><br \/>\nNote, that if an essential function of your application is taking pictures, then restrict its visibility on Google Play to devices that have a camera. To advertise that your application depends on having a camera, put a  tag in your manifest file.<\/div>\n<h2>6. Build, compile and run<\/h2>\n<p>When we build, compile and run our project, the main AndroidCameraExample should look like this:<\/p>\n<p><figure id=\"attachment_14193\" aria-describedby=\"caption-attachment-14193\" style=\"width: 711px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/AndroidCameraExample-5.jpg\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/AndroidCameraExample-5.jpg\" alt=\"Figure 8. Figure This is how the main Activity looks like\" width=\"711\" height=\"400\" class=\"size-full wp-image-14193\"><\/a><figcaption id=\"caption-attachment-14193\" class=\"wp-caption-text\">Figure 8. Figure This is how the main Activity looks like.<\/figcaption><\/figure><\/p>\n<h2>Download the Eclipse Project<\/h2>\n<p>This was an example of Android AndroidCameraExample.<\/p>\n<div class=\"download\"><strong>Download<br \/>\n<\/strong>You can download the full source code of this example here:  <a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/AndroidCameraExample.zip\"><strong>AndroidCameraExample<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In our previous Android Example, we tried to explain the use of Android SurfaceView through a simple camera application. In the meantime, we realized how important is the &#8220;camera mode&#8221; in a simple and modern Android application, as nowadays it is becoming very common, that the camera is used not only to capture basic portraits &hellip;<\/p>\n","protected":false},"author":14,"featured_media":1202,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[717],"tags":[],"class_list":["post-15199","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-camera-hardware"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Android Camera Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"In our previous Android Example, we tried to explain the use of Android SurfaceView through a simple camera application. In the meantime, we realized how\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/android\/core\/hardware\/camera-hardware\/android-camera-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Android Camera Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"In our previous Android Example, we tried to explain the use of Android SurfaceView through a simple camera application. In the meantime, we realized how\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/android\/core\/hardware\/camera-hardware\/android-camera-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2014-10-10T09:10:05+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-04-24T12:59:47+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Chryssa Aliferi\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Chryssa Aliferi\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"12 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/hardware\/camera-hardware\/android-camera-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/hardware\/camera-hardware\/android-camera-example\/\"},\"author\":{\"name\":\"Chryssa Aliferi\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/863144453b9fc15d4184d71833dcf332\"},\"headline\":\"Android Camera Example\",\"datePublished\":\"2014-10-10T09:10:05+00:00\",\"dateModified\":\"2019-04-24T12:59:47+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/hardware\/camera-hardware\/android-camera-example\/\"},\"wordCount\":1053,\"commentCount\":5,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/hardware\/camera-hardware\/android-camera-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\",\"articleSection\":[\"Camera\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/android\/core\/hardware\/camera-hardware\/android-camera-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/hardware\/camera-hardware\/android-camera-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/hardware\/camera-hardware\/android-camera-example\/\",\"name\":\"Android Camera Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/hardware\/camera-hardware\/android-camera-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/hardware\/camera-hardware\/android-camera-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\",\"datePublished\":\"2014-10-10T09:10:05+00:00\",\"dateModified\":\"2019-04-24T12:59:47+00:00\",\"description\":\"In our previous Android Example, we tried to explain the use of Android SurfaceView through a simple camera application. In the meantime, we realized how\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/hardware\/camera-hardware\/android-camera-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/android\/core\/hardware\/camera-hardware\/android-camera-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/hardware\/camera-hardware\/android-camera-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/hardware\/camera-hardware\/android-camera-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Android\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/android\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"core\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"hardware\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/hardware\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Camera\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/hardware\/camera-hardware\/\"},{\"@type\":\"ListItem\",\"position\":6,\"name\":\"Android Camera Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/863144453b9fc15d4184d71833dcf332\",\"name\":\"Chryssa Aliferi\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/03\/Chryssa-Aliferi-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/03\/Chryssa-Aliferi-96x96.jpg\",\"caption\":\"Chryssa Aliferi\"},\"description\":\"Chryssa is a Computer Science graduate from Athens University of Economic and Business. During her studies, Chryssa carried out a great variety of projects ranging from networking to software engineering. She is very keen on front end development especially on mobile technologies and web applications. She has worked as a junior Software Engineer in the telecommunications area and currently works as an Android Developer.\",\"sameAs\":[\"http:\/\/www.javacodegeeks.com\/\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/chryssa-aliferi\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Android Camera Example - Java Code Geeks","description":"In our previous Android Example, we tried to explain the use of Android SurfaceView through a simple camera application. In the meantime, we realized how","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/android\/core\/hardware\/camera-hardware\/android-camera-example\/","og_locale":"en_US","og_type":"article","og_title":"Android Camera Example - Java Code Geeks","og_description":"In our previous Android Example, we tried to explain the use of Android SurfaceView through a simple camera application. In the meantime, we realized how","og_url":"https:\/\/examples.javacodegeeks.com\/android\/core\/hardware\/camera-hardware\/android-camera-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2014-10-10T09:10:05+00:00","article_modified_time":"2019-04-24T12:59:47+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","type":"image\/jpeg"}],"author":"Chryssa Aliferi","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Chryssa Aliferi","Est. reading time":"12 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/hardware\/camera-hardware\/android-camera-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/hardware\/camera-hardware\/android-camera-example\/"},"author":{"name":"Chryssa Aliferi","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/863144453b9fc15d4184d71833dcf332"},"headline":"Android Camera Example","datePublished":"2014-10-10T09:10:05+00:00","dateModified":"2019-04-24T12:59:47+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/hardware\/camera-hardware\/android-camera-example\/"},"wordCount":1053,"commentCount":5,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/hardware\/camera-hardware\/android-camera-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","articleSection":["Camera"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/android\/core\/hardware\/camera-hardware\/android-camera-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/hardware\/camera-hardware\/android-camera-example\/","url":"https:\/\/examples.javacodegeeks.com\/android\/core\/hardware\/camera-hardware\/android-camera-example\/","name":"Android Camera Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/hardware\/camera-hardware\/android-camera-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/hardware\/camera-hardware\/android-camera-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","datePublished":"2014-10-10T09:10:05+00:00","dateModified":"2019-04-24T12:59:47+00:00","description":"In our previous Android Example, we tried to explain the use of Android SurfaceView through a simple camera application. In the meantime, we realized how","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/hardware\/camera-hardware\/android-camera-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/android\/core\/hardware\/camera-hardware\/android-camera-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/hardware\/camera-hardware\/android-camera-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/hardware\/camera-hardware\/android-camera-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Android","item":"https:\/\/examples.javacodegeeks.com\/category\/android\/"},{"@type":"ListItem","position":3,"name":"core","item":"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/"},{"@type":"ListItem","position":4,"name":"hardware","item":"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/hardware\/"},{"@type":"ListItem","position":5,"name":"Camera","item":"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/hardware\/camera-hardware\/"},{"@type":"ListItem","position":6,"name":"Android Camera Example"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/863144453b9fc15d4184d71833dcf332","name":"Chryssa Aliferi","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/03\/Chryssa-Aliferi-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/03\/Chryssa-Aliferi-96x96.jpg","caption":"Chryssa Aliferi"},"description":"Chryssa is a Computer Science graduate from Athens University of Economic and Business. During her studies, Chryssa carried out a great variety of projects ranging from networking to software engineering. She is very keen on front end development especially on mobile technologies and web applications. She has worked as a junior Software Engineer in the telecommunications area and currently works as an Android Developer.","sameAs":["http:\/\/www.javacodegeeks.com\/"],"url":"https:\/\/examples.javacodegeeks.com\/author\/chryssa-aliferi\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/15199","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/14"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=15199"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/15199\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1202"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=15199"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=15199"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=15199"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}