Picture is not showing up in my activity after I take a photo

30 Views Asked by At

On Android 10 and below, when I take a picture using the code below, everything is fine except for Android 11 and above.

private fun openCameraApp() {
        val photoURI: Uri = FileProvider.getUriForFile(
            this,
            "com.example.android.fileprovider",

        appFolder


    )
    refresh()
    val cameraIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
    cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI)
    println("::Camera result::  ${photoURI}")

    resultLauncher.launch(cameraIntent)
}
1

There are 1 best solutions below

0
Syed Rafaqat Hussain On

Since API level 30 (Android 11), there have been changes in the package visibility.

For your package manager to work properly, you need to declare <queries> in your Androidmanifest.xml file

Code.

<manifest package="your.package.name">
<queries>
    <intent>
        <action android:name="android.media.action.IMAGE_CAPTURE" />
    </intent>
</queries>
</manifest>

This will only be worked for android default camera apps

Happy Coding :)