Back to project page iSlide.
The source code is released under:
MIT License
If you think the Android project iSlide listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package edu.csun.group2.islide; /*from w w w . j a v a2 s . c o m*/ import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.hardware.Camera; import android.hardware.Camera.CameraInfo; import android.hardware.Camera.PictureCallback; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.FrameLayout; public class TakePictureActivity extends Activity { private final static String DEBUG_TAG = "MakePhotoActivity"; // private Camera camera; private int cameraId = 0; private Camera mCamera; private CameraPreview mPreview; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_take_picture); // Create an instance of Camera mCamera = getCameraInstance(); // Create our Preview view and set it as the content of our activity. mPreview = new CameraPreview(this, mCamera); FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview); preview.addView(mPreview); } public void onClick(View view) { if (mCamera != null) { // camera = Camera.open(cameraId); mCamera.takePicture(null, null, new PhotoHandler( TakePictureActivity.this)); // new PhotoHandler(getApplicationContext())); } } public static Camera getCameraInstance() { Camera c = null; try { c = Camera.open(); // attempt to get a Camera instance } catch (Exception e) { // Camera is not available (in use or does not exist) } return c; // returns null if camera is unavailable } private int findBackFacingCamera() { int cameraId = -1; // Search for the front facing camera int numberOfCameras = Camera.getNumberOfCameras(); for (int i = 0; i < numberOfCameras; i++) { CameraInfo info = new CameraInfo(); Camera.getCameraInfo(i, info); if (info.facing == CameraInfo.CAMERA_FACING_BACK) { Log.d(DEBUG_TAG, "Camera found"); cameraId = i; break; } } return cameraId; } @Override protected void onPause() { if (mCamera != null) { mCamera.release(); mCamera = null; } super.onPause(); } private boolean checkCameraHardware(Context context) { if (context.getPackageManager().hasSystemFeature( PackageManager.FEATURE_CAMERA)) { // this device has a camera return true; } else { // no camera on this device return false; } } }