I use this code to get a picture from camera and put it on imageview:
private void openCamera()
{
mMediaUri =getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
Instead of return Uri.fromFile(mediaFile);
do
return FileProvider.getUriForFile(MainActivity.this,
BuildConfig.APPLICATION_ID + ".provider",
mediaFile);
That would require you to add a provider to the AndroidManifest
:
For AndroidX, use androidx.core.content.FileProvider
And then create a provider_paths.xml
file in xml folder under res folder.
Read more: Full article