Flutter相机包适用于针对Android API版本30的应用程序权限

3
我最近将我的一个flutter应用程序的目标sdk升级到30。然后,拍照功能就无法正常工作了。出现了此链接中提到的错误:
PlatformException(no_available_camera, No cameras available for taking pictures., null)。
这与Android 11中的包可见性变更有关。现在,在第一个链接中有一个解决方案,通过在清单文件中添加以下行来查询设备上安装的所有软件包的权限。
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>

对我而言,这是有效的。但query_all_packages文档说:

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.

这意味着,仅仅为了相机应用程序,我们不应该请求所有已安装程序的权限。现在我的问题是,应该在Android清单文件中添加什么以显示相机包?谢谢提前。

1个回答

5
如果您的应用程序针对Android 11(API级别30)或更高版本进行目标设置,则系统会自动将某些应用程序显示给您的应用程序,但默认情况下会隐藏其他应用程序。
详情请参见此处。

https://developer.android.com/training/basics/intents/package-visibility

如果要在API级别30及更高的设备上使用相机拍照,您需要将以下行添加到清单中:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接