This code works fine with the camera in android versions below 6.0. But with version 6.0 gives an error in the use of the camera. How can I fix this error?
public class MainActivity extends AppCompatActivity { private final String TAG = this.getClass().getName(); ImageView ivCamera, ivGallery, ivUpload, ivImage; CameraPhoto cameraPhoto; GalleryPhoto galleryPhoto; final int CAMERA_REQUEST = 13323; final int GALLERY_REQUEST = 22131; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); } }); cameraPhoto = new CameraPhoto(getApplicationContext()); galleryPhoto = new GalleryPhoto(getApplicationContext()); ivImage = (ImageView)findViewById(R.id.ivImage); ivCamera = (ImageView)findViewById(R.id.ivCamera); ivGallery = (ImageView)findViewById(R.id.ivGallery); ivUpload = (ImageView)findViewById(R.id.ivUpload); ivCamera.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { startActivityForResult(cameraPhoto.takePhotoIntent(), CAMERA_REQUEST); cameraPhoto.addToGallery(); } catch (IOException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "Something Wrong while taking photos", Toast.LENGTH_SHORT).show(); } } }); ivGallery.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivityForResult(galleryPhoto.openGalleryIntent(), GALLERY_REQUEST); } }); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(resultCode == RESULT_OK){ if(requestCode == CAMERA_REQUEST){ String photoPath = cameraPhoto.getPhotoPath(); try { Bitmap bitmap = ImageLoader.init().from(photoPath).requestSize(512, 512).getBitmap(); ivImage.setImageBitmap(bitmap); } catch (FileNotFoundException e) { Toast.makeText(getApplicationContext(), "Something Wrong while loading photos", Toast.LENGTH_SHORT).show(); } } else if(requestCode == GALLERY_REQUEST){ Uri uri = data.getData(); galleryPhoto.setPhotoUri(uri); String photoPath = galleryPhoto.getPath(); try { Bitmap bitmap = ImageLoader.init().from(photoPath).requestSize(512, 512).getBitmap(); ivImage.setImageBitmap(bitmap); } catch (FileNotFoundException e) { Toast.makeText(getApplicationContext(), "Something Wrong while choosing photos", Toast.LENGTH_SHORT).show(); } } } } } 

