首页 > 解决方案 > 针对 Android api 版本 30 的应用的 Flutter 相机包权限

问题描述

我最近将我的一个颤振应用程序的目标 sdk 升级到了 30。之后,拍照不起作用。它显示了此链接中提到的错误。

PlatformException(no_available_camera, 没有可用于拍照的相机。, 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 清单中添加什么来提高相机包的可见性?提前致谢。

标签: androidflutteruser-permissionsandroid-11

解决方案


如果您的应用面向 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>

推荐阅读