Reputation: 2375
I have recently upgraded one of my flutter app's target sdk to 30. And after that, taking photo isn't working. Its showing the error mentioned in this link.
PlatformException(no_available_camera, No cameras available for taking pictures., null).
It's something to do with the package visibility changes in android 11. Now there have a solution in the first link which is adding a permission for querying all packages installed in the device by adding the following line in the manifest file.
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
Which works for me. But the documentation of query_all_packages says the following:
In the vast majority of cases, however, it's possible to fulfill your app's use cases by
interacting with the set of apps that are visible automatically and by declaring the other
apps that your app needs to access in your manifest file. To respect user privacy, your app
should request the smallest amount of package visibility necessary in order for your app to
work.
In an upcoming policy update, look for Google Play to provide guidelines for apps that need
the QUERY_ALL_PACKAGES permission.
That means, just for the camera app we shouldn't ask for the permissions for all installed packages. Now my question is, what should be added in the android manifest for camera package visibility? Thanks in advance.
Upvotes: 3
Views: 2539
Reputation: 170
If your app is targeting Android 11(API level 30) or higher, the system makes some apps visible to your app automatically, but it hides other apps by default.
The details can be found here,
https://developer.android.com/training/basics/intents/package-visibility
For using the camera to take a photo in API level 30 and higher devices you need to add this below lines to your manifest,
<queries>
<intent>
<action android:name="android.media.action.IMAGE_CAPTURE" />
</intent>
</queries>
Upvotes: 5