每次USB设备断开时,我都试图阻止我正在开发的应用程序请求USB权限。我一直在跟踪:USB device access pop-up suppression?没有多少运气。
该应用程序确实记得USB设备,直到设备拔出为止。
如果这件事重要的话,我正在尝试将这个应用程序连接到一个Arduino Teensy。
这就是我的清单活动的样子
<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连接时:如果用户接受,您的应用程序将自动拥有访问设备的权限,直到设备断开为止。
我还想指出,建议的重复并不像我试图解决的问题一样。他们的问题是有两个活动,而我的问题只处理一个。
https://developer.android.com/guide/topics/connectivity/usb/host
发布于 2019-03-26 20:10:15
当USB插入手机时,我们会自动打开应用程序,因为我们的项目处理的应用程序整天都在打开。
该应用程序只要求允许在手机上使用USB一次,并且现在记住它,只要用户在打开应用程序之前连接USB,并且手机是解锁的。手机甚至会在手机重新启动后记住许可。
这是一项工作,但它适用于我们的需要。希望这能帮助其他人解决同样的问题。
发布于 2019-01-30 21:26:18
正如提问者here说的,对于您的优点(如果我理解正确的话),下面的内容应该足够了。这是对的,他有一个不同的问题,但他开始他的问题,说,对你的情况,这是可行的。
<activity android:name=".FirstActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<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>https://stackoverflow.com/questions/54298521
复制相似问题