gpt4 book ai didi

java - Android 应用程序不会记住 USB 权限

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:17:32 25 4
gpt4 key购买 nike

我试图阻止我正在使用的应用程序在每次断开 USB 设备时请求 USB 权限。我已关注:USB device access pop-up suppression?没有太多运气。

应用会记住 USB 设备,直到设备被拔掉。

如果重要的话,我正在尝试将应用程序连接到 Arduino Teensy。

这是我的 list Activity 的样子

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter> <!-- For receiving data from another application -->
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"/>
</intent-filter>
<meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" android:resource="@xml/usb_device_filter" />

</activity>
</application>

这是我的 usb_device_filter 文件:

<?xml version="1.0" encoding="utf-8"?>

<resources>
<usb-device vendor-id="--hidden--" product-id="--hidden--" />
</resources>

欢迎任何帮助。

编辑:我还查看了 Android 开发者页面,他们说在对 USB 连接使用 Intent 过滤器时:如果用户接受,您的应用程序将自动获得访问设备的权限,直到设备断开连接。

我还想指出,建议的副本与我试图解决的问题不同。他们的问题是有两项 Activity ,而我的问题只涉及一项。

https://developer.android.com/guide/topics/connectivity/usb/host

最佳答案

我们最终在将 USB 插入手机时自动打开应用程序,因为我们的项目处理应用程序全天打开的问题。

只要用户在打开应用程序之前连接 USB 并且手机已解锁,该应用程序只需要为手机请求一次使用 USB 的权限并立即记住它。手机甚至会在手机重启后记住权限。

这是一种解决方法,但它可以满足我们的需求。希望这会帮助其他一些遇到同样问题的人。

关于java - Android 应用程序不会记住 USB 权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54298521/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com