When I click on capture photo icon in my application, by default it should open front camera but every time it is opening back camera. I need to change it manually to open front camera.
So can anyone please help me out on the above issue.
Below is my code to open front camera mode .
private void getPhotoFromCamera()
{
try
{
PackageManager pm = mContext.getPackageManager();
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra("android.intent.extras.CAMERA_FACING",1);
VisitorRegistrationFragment.this.startActivityForResult(intent,FROM_CAMERA);
}
catch (Exception e)
{
e.printStackTrace();
}
catch (OutOfMemoryError e)
{
e.printStackTrace();
}
}
Change to use front camera
Hardcoding this values is a bad idea and should better use
I think you must add this in your onCreate() method :
It worked for me. Hope so it might be helpful for you too.
This is code to open front camera My javafile :
my Xml File:
two permission needed :-
Add the following permissions in the AndroidManifest.xml file: