Example usage for android.hardware Camera open

List of usage examples for android.hardware Camera open

Introduction

In this page you can find the example usage for android.hardware Camera open.

Prototype

public static Camera open() 

Source Link

Document

Creates a new Camera object to access the first back-facing camera on the device.

Usage

From source file:com.bringcommunications.etherpay.ScanActivity.java

/** A safe way to get an instance of the Camera object. */
public static Camera getCameraInstance() {
    Camera c = null;/*from   ww  w. ja  va  2 s. c  o  m*/
    try {
        c = Camera.open();
    } catch (Exception e) {
        System.out.println(e.toString());
    }
    return c;
}

From source file:edu.winlab.minijarvis.activity.CameraActivity.java

/**
 * To get camera instance/*from  www . jav  a 2  s.c  om*/
 * @return Camera
 */
private static Camera getCameraInstance() {
    Camera camera = null;
    try {
        camera = Camera.open();

        // Work around for Camera preview issues
        Camera.Parameters params = camera.getParameters();
        params.setPreviewFpsRange(30000, 30000);
        camera.setParameters(params);
    } catch (Exception e) {
        System.out.println(e.toString());
        e.printStackTrace();
    }
    return camera;
}

From source file:runtmobile.udea.edu.co.runtmobile.Capture.java

@Override
public void surfaceCreated(SurfaceHolder holder) {
    // TODO Auto-generated method stub
    camera = Camera.open();
    camera.setDisplayOrientation(90);/*from  ww  w  . j  a  v a2s. co  m*/
    try {
        camera.setPreviewDisplay(holder);
        // Encendemos la camara
        camera.startPreview();
    } catch (IOException e) {
        Log.e("IOException", "Ha sucedido un error al iniciar la configuracin de la camara", e);
    }
}

From source file:com.sveder.cardboardpassthrough.MainActivity.java

public void startCamera(int texture) {
    surface = new SurfaceTexture(texture);
    surface.setOnFrameAvailableListener(this);

    camera = Camera.open();

    try {//from   w  w w  .jav  a  2s.  com
        camera.setPreviewTexture(surface);
        camera.startPreview();
    } catch (IOException ioe) {
        Log.w("MainActivity", "CAM LAUNCH FAILED");
    }
}

From source file:u.ready_wisc.MenuActivity.java

@Override
public void onClick(View v) {
    //TODO fix action bar or disable completely
    if ((v.getId() == (R.id.prepareButton)) || (v.getId() == (R.id.prepareMenuButton))) {
        Intent i = new Intent(MenuActivity.this, Prep_Main.class);
        startActivity(i);//from  www . j  a  v a  2 s  . c  o m
    } else if (v.getId() == (R.id.reportDamageButton) || v.getId() == (R.id.emergencyMenuButton)) {
        Intent i = new Intent(MenuActivity.this, Emergency.class);
        MenuActivity.this.startActivity(i);
    } else if (v.getId() == (R.id.disasterResourcesButton) || v.getId() == (R.id.disasterMenuButton)) {
        Intent i = new Intent(MenuActivity.this, ResourcesActivity.class);
        MenuActivity.this.startActivity(i);
    } else if (v.getId() == (R.id.typeDisasterButton)) {
        Intent i = new Intent(MenuActivity.this, DisastersType.class);
        MenuActivity.this.startActivity(i);
    } else if (v.getId() == (R.id.SOSMenubutton)) {
        if (!sosTone) {

            //sets device volume to maximum
            AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
            am.setStreamVolume(AudioManager.STREAM_MUSIC, am.getStreamMaxVolume(AudioManager.STREAM_MUSIC), 0);

            //begins looping tone
            mp.setLooping(true);
            sosTone = true;
            mp.start();
        }

    } else if (v.getId() == (R.id.FlashlightMenuButton)) {
        //check to see if device has a camera with flash
        if (!pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {

            Log.e("err", "Device has no camera!");
            //Return from the method, do nothing after this code block
            return;
        }
        // if camera has flash toggle on and off
        else {
            // boolean to check status of camera flash
            if (!isFlashOn) {

                //if flash is off, toggle boolean to on and turn on flash
                isFlashOn = true;
                camera = Camera.open();
                Camera.Parameters parameters = camera.getParameters();
                parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
                camera.setParameters(parameters);
                camera.startPreview();

            } else {

                //if flash is on turn boolean to false and turn off flash
                isFlashOn = false;
                camera.stopPreview();
                camera.release();
                camera = null;

            }
        }
    } else {

        //stops looping sound
        Log.d("Sound test", "Stopping sound");
        mp.setLooping(false);
        mp.pause();
        sosTone = false;
    }
}

From source file:com.example.hudpassthrough.BluetoothChat.java

@Override
public synchronized void onResume() {
    if (mCamera == null) {
        mCamera = Camera.open();
        //mCamera.enableShutterSound(false); //Questionable Legality!
    }/* w ww.  jav a 2 s  .co m*/
    super.onResume();
    // Performing this check in onResume() covers the case in which BT was
    // not enabled during onStart(), so we were paused to enable it...
    // onResume() will be called when ACTION_REQUEST_ENABLE activity returns.
    if (mChatService != null) {
        // Only if the state is STATE_NONE, do we know that we haven't started already
        if (mChatService.getState() == BluetoothChatService.STATE_NONE) {
            // Start the Bluetooth chat services
            mChatService.start();
        }
    }
}

From source file:com.example.android.foldinglayout.FoldingLayoutActivity.java

/**
 * Creates a SurfaceTextureListener in order to prepare a TextureView
 * which displays a live, and continuously updated, feed from the Camera.
 *///from  w w w. jav a2 s  . c om
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private TextureView.SurfaceTextureListener createSurfaceTextureListener() {
    if (hasApiLevel(Build.VERSION_CODES.ICE_CREAM_SANDWICH)) {
        return new TextureView.SurfaceTextureListener() {
            @Override
            public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int i, int i2) {
                mCamera = Camera.open();

                if (mCamera == null && Camera.getNumberOfCameras() > 1) {
                    mCamera = mCamera.open(Camera.CameraInfo.CAMERA_FACING_FRONT);
                }

                if (mCamera == null) {
                    return;
                }

                try {
                    mCamera.setPreviewTexture(surfaceTexture);
                    mCamera.setDisplayOrientation(90);
                    mCamera.startPreview();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int i, int i2) {
                // Ignored, Camera does all the work for us
            }

            @Override
            public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {
                if (mCamera != null) {
                    mCamera.stopPreview();
                    mCamera.release();
                }
                return true;
            }

            @Override
            public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
                // Invoked every time there's a new Camera preview frame
            }
        };
    } else {
        return null;
    }
}

From source file:com.raffaele.squarecash4glass.CVVConfirmActivity.java

/**
 * Safe method for getting a camera instance.
 * /* ww  w.java  2 s.co  m*/
 * @return
 */
public static Camera getCameraInstance() {
    Camera c = null;
    try {
        c = Camera.open(); // attempt to get a Camera instance
    } catch (Exception e) {
        e.printStackTrace();
    }
    return c; // returns null if camera is unavailable
}

From source file:com.allthingsgeek.celljoust.MainActivity.java

public void surfaceCreated(SurfaceHolder holder) {
    mCamera = Camera.open();
    try {//  w w w.  ja  va2s.  c om
        mCamera.setPreviewDisplay(holder);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:edu.mit.mobile.android.livingpostcards.CameraActivity.java

/** A safe way to get an instance of the Camera object. */
public static Camera getCameraInstance() {
    Camera c = null;/*  w  w  w  .  j a  va2s.com*/
    try {
        c = Camera.open(); // attempt to get a Camera instance
        final Parameters params = c.getParameters();
        final Size s = getBestPictureSize(640, 480, params);
        params.setPictureSize(s.width, s.height);
        if (Constants.DEBUG) {
            Log.d(TAG, "best picture size is " + s.width + "x" + s.height);
        }
        c.setParameters(params);
    } catch (final Exception e) {
        Log.e(TAG, "Error acquiring camera", e);
    }
    return c; // returns null if camera is unavailable
}