I want to detect which camera that my user used to capture an image, to then initialize a value according to the type (Front/Rear camera).
The following is my trying, After I run the app, value is always 0.417 !
public class Home extends Activity {
double value = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.MainActivity);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
input = new EditText(this);
builder.setView(input);
builder.setPositiveButton("Next", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int witch) {
Intent camera_intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = getFile();
camera_intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
startActivityForResult(camera_intent, CAM_REQUEST);
}
});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAM_REQUEST && resultCode == RESULT_OK) {
Intent intent = new Intent(this, Enrollment.class);
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
this.value = 0.417;
}
else if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK){
this.value = 0.5;
}
startActivity(intent);
}
}
BTW, capture image work perfectly, I just need to determine the type of camera (front or rear).