android - 在 flutter 中访问外部摄像头时出错 - "The user has not given permission to access the device"

标签 android flutter dart channel

我想通过我的平板电脑访问 USB 网络摄像头。
我下载了这个项目用于学习和测试目的。它完美地工作。相机打开,拍照并保存。
project - github
我在flutter中创建了一个项目,并建立了一个通信 channel 来访问应用程序。
但是当我尝试打开相机的那一刻,我得到了消息:

User has not given 10404/com.example.monitoramento permission to access device /dev/bus/usb/001/002


我有一个 device_filter.xml 文件,我在其中添加了设备 PID 和 VID:
<?xml version="1.0" encoding="utf-8"?>

<usb>
    <usb-device class="239" subclass="2" /> <!-- all device of UVC -->
    <!-- a few android 9.0 -->
    <usb-device class="14" subclass="9" />
    <usb-device class="2" subclass="0" />
    <usb-device class="6" subclass="-1" />
    <usb-device class="39" subclass="0" />
    <usb-device product-id="4836" vendor-id="9573" />
    <usb-device product-id="2229" vendor-id="1133" />
    <usb-device product-id="640" vendor-id="1409" />
    <usb-device product-id="258" vendor-id="9228" />
    <usb-device product-id="2074" vendor-id="1133" />

</usb>

还会报告这些错误。
enter image description here
我很感激任何评论!

最佳答案

与类似的应用程序( https://github.com/shengjunhu/android_uvc_camera )相同的问题。两个应用程序的 UI 看起来都一样,甚至有相同的标题(UVCCamera),这让我怀疑它们与基因有关。
Android 要求应用程序在访问 USB 设备之前获得许可。据我了解,有两种方法可以做到这一点:

  • 为应用定义一个 Intent 过滤器。如果连接了匹配的 USB 设备,则会提示用户允许应用程序访问 USB 设备,然后启动应用程序。在这种情况下,应用程序已经拥有权限。 Intent 过滤器需要一个设备列表来监听,例如device_filter.xml .
  • 如果应用程序扫描设备而不是等待通知,则必须明确获得许可。这很像其他运行时权限,如 https://developer.android.com/guide/topics/connectivity/usb/host.html#permission-d 中所述。 .

  • 如果您的应用程序扫描 USB 摄像头设备而不是监听 Intent ,则第一个选项不可用并修改 device_filter.xml没有效果。发现摄像头后,您必须请求权限并推迟摄像头访问权限,直到获得权限。

    关于android - 在 flutter 中访问外部摄像头时出错 - "The user has not given permission to access the device",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70130204/

    相关文章:

    java - Android @drawable/logos.png 报错logos.png is incompatible with attribute android :res

    flutter - 如何为Flutter中的所有设备将小部件与Media Query对齐?

    dart - Flutter:如何在不复制整个文件的情况下调整/覆盖 Flutter 核心代码的属性?

    ios - 使用 firebase-auth 时在 ios 上构建应用程序会导致 flutter 问题

    android - 视差效果和捕捉工具栏,如 Google Play 商店应用

    android - Cordova平台添加android报错

    flutter - [SOLVED]更新错误:成功发送HTTP发布后,我在Microsoft SQL Server中的数据没有更改(200)

    flutter - copyWith() 函数有什么作用?

    java - 无法解析符号 'setOnClickListener' - Android Studio

    java - 需要 keycode_home 的帮助