I have also faced the same issue in Android N devices. But i resolved it.
Here is my code which can solve the issue:
public void launchCamera() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
intent.putExtra(MediaStore.EXTRA_OUTPUT, getPhotoFileUri());
} else {
File file = new File(getPhotoFileUri().getPath());
Uri photoUri = FileProvider.getUriForFile(getApplicationContext(), getApplicationContext().getPackageName() + ".provider", file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
}
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
if (intent.resolveActivity(getApplicationContext().getPackageManager()) != null) {
startActivityForResult(intent, REQUEST_CAMERA);
}
}
After this you need to create a XML folder in res, and in that folder you need to create a xml labeled provider_paths.xml
Code in provider_paths.xml
Later in manifest you need to add the following inside the application tag and make sure that the compileSdkVersion >=24
Here are the two reference links which can guide you better for better understanding.
Links:
link1 - from medium cooperation
link2 - from inthecheesefactory