The important thing in Android 6.0 is to request the permissions for the camera, for this you can use this method:
private void checkCameraPermission() {
int permissionCheck = ContextCompat.checkSelfPermission(
this, Manifest.permission.CAMERA);
if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
Log.i("Mensaje", "No se tiene permiso para la Camara.");
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, 225);
} else {
Log.i("Mensaje", "Se tiene permiso para usar la camara!");
}
}
Here is an example of how to open the camera:
How to open a phone's camera from Android? and you can review details in the documentation.
What you would do is, from a button add a listener which activates the camera:
Button botonCamera = (Button)findViewById(R.id.mybutton);
botonCamera.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try{
mCamera = Camera.open();
} catch (Exception e){
Log.d("ERROR", "Failed to get camera: " + e.getMessage());
}
if(mCamera != null) {
mCameraView = new CameraView(this, mCamera);
FrameLayout camera_view = (FrameLayout)findViewById(R.id.camera_view);
camera_view.addView(mCameraView);//agrega la vista CameraView()
}
}
});
But if you want to save the photos in a specific path you can do it by trying:
Button botonCamera = (Button)findViewById(R.id.mybutton);
botonCamera.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Uri uriSavedImage = Uri.fromFile(new File("/sdcard/mi_folder/mi_foto.png"));
camera.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
startActivityForResult(camera, 1);
}
});