0

I'm using an old phone it's rear camera is damaged so I want to set my default camera as my front camera. Is it possible to do that everytime when I open camera app it open front camera always?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Vishal g
  • 21
  • 1
  • 3
  • If you have root permission, try hooking the camera related methods. – KYHSGeekCode Aug 12 '18 at 22:35
  • 1. Root root your phone. 2.Install xposed framework. 3. Look for camera.open() method in android source code. 4. Hook that method so that the method opens camera1. – KYHSGeekCode Aug 13 '18 at 08:12

3 Answers3

1

Try this!

Camera.open(android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT);//avoid passing hardcode values
Tara
  • 692
  • 5
  • 23
0
Camera mCamera;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

   mCamera= Camera.open(1);
}

Note:

0 for CAMERA_FACING_BACK

1 for CAMERA_FACING_FRONT

sasikumar
  • 12,540
  • 3
  • 28
  • 48
0

This might helpful. Source URL : this

Button otherCamera = (Button) findViewById(R.id.OtherCamera);

otherCamera.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (inPreview) {
    camera.stopPreview();
}
//NB: if you don't release the current camera before switching, you app will crash
camera.release();

//swap the id of the camera to be used
if(currentCameraId == Camera.CameraInfo.CAMERA_FACING_BACK){
    currentCameraId = Camera.CameraInfo.CAMERA_FACING_FRONT;
}
else {
    currentCameraId = Camera.CameraInfo.CAMERA_FACING_BACK;
}
camera = Camera.open(currentCameraId);

try {

    camera.setPreviewDisplay(previewHolder);
} catch (IOException e) {
    e.printStackTrace();
}
camera.startPreview();
}
Waseem
  • 439
  • 3
  • 18