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
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="."/>
</paths>
Later in manifest you need to add the following inside the application tag and make sure that the compileSdkVersion >=24
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
Here are the two reference links which can guide you better for better understanding.
Links:
link1 - from medium cooperation
link2 - from inthecheesefactory