Note that there are some explanatory texts on larger screens.

plurals
  1. POhow can i detect the front camera and use to capture an image?
    text
    copied!<p>I have my codes here that captured an image automatically using back camera and saved it to the gallery, my problem is, I want the front camera to use to capture an image. How can i detect the front camera? I really need help for this.</p> <pre><code>/** Called when the activity is first created. */ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main); iv_image = (ImageView) findViewById(R.id.imageView); sv = (SurfaceView) findViewById(R.id.surfaceView); sHolder = sv.getHolder(); sHolder.addCallback(this); sHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } @Override public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { parameters = mCamera.getParameters(); mCamera.setParameters(parameters); //mCamera.startPreview(); Camera.PictureCallback mCall = new Camera.PictureCallback() { @Override public void onPictureTaken(byte[] data, Camera camera) { Uri uriTarget = getContentResolver().insert (Media.EXTERNAL_CONTENT_URI, new ContentValues()); OutputStream imageFileOS; try { imageFileOS = getContentResolver().openOutputStream(uriTarget); imageFileOS.write(data); imageFileOS.flush(); imageFileOS.close(); Toast.makeText(TakePictureActivity.this, "Image saved: " + uriTarget.toString(), Toast.LENGTH_LONG).show(); } catch (FileNotFoundException e) { e.printStackTrace(); }catch (IOException e) { e.printStackTrace(); } mCamera.startPreview(); bmp = BitmapFactory.decodeByteArray(data, 0, data.length); iv_image.setImageBitmap(bmp); } }; mCamera.takePicture(null, null, mCall); } @Override public void surfaceCreated(SurfaceHolder holder) { mCamera = Camera.open(); try { mCamera.setPreviewDisplay(holder); } catch (IOException exception) { mCamera.release(); mCamera = null; } } @Override public void surfaceDestroyed(SurfaceHolder holder) { mCamera.stopPreview(); mCamera.release(); mCamera = null; } </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload