Android的USB设备的许可和意图过滤器 [英] Android USB Device Permission and Intent Filter

查看:933
本文介绍了Android的USB设备的许可和意图过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android应用程序将与USB设备进行交互,在的就取得许可与设备它交流Android开发者官方文件说:

I have an Android App which will interact with an USB device, in the Android developer official documentation for Obtaining permission to communicate with a device it says:

注意:如果应用程序使用一个意图过滤器,因为它们可以连接到发现的USB设备,它会自动接收权限,如果用户允许应用程序来处理这个意图。如果没有,你必须明确地请求允许在你的应用程序连接到该设备之前。

Note: If your application uses an intent filter to discover USB devices as they're connected, it automatically receives permission if the user allows your application to handle the intent. If not, you must request permission explicitly in your application before connecting to the device.

的意图过滤器是在AndroidManifest.xml中声明,并使用资源文件,其中将包括厂商ID和产品ID。

The Intent Filter is to be declared in the AndroidManifest.xml and using a resource file which will include the vendor-id and product-id.

如果我插入我的设备没有任何反应,即使有申报意向。 所以,我必须使用在其中明确涉及请求允许相同的官方文件中提到的方法。

If i plug my device nothing happens, even with the declared Intent. So i have to use the method mentioned in the same official documentation which involves explicitly asking for permission.

这工作,我可以与设备进行通信,但是它发生的用户应用程序每次启动时给予的权限,或者该设备重新连接。最终这将present一个消息给用户的设备被插入和应用程序启动,并给予相同的权限,每次是不可取的每次请求确认。

This works and i can communicate with the device, but it happens that the user has to give the permission each time the app is started, or the device reconnected. In the end this will present a message to the user asking for confirmation each time the device is plugged and the application started, and giving the same permission each time is not desirable.

因此​​,如果......自动获得许可......一部分是行不通的。

So if the "... automatically receives permission ..." part is not working.

如何让我的意图过滤器的工作?
我在想什么?
我还有其他的选择吗?

How do i make the intent filter to work?
What am i missing?
Do i have any other alternatives?

此问题:<一href="http://stackoverflow.com/questions/14274285/android-usb-permissions-dialog-never-appears">Android USB权限对话框永远不会出现了相反的问题,但解决的办法会不会为我工作。
使得应用系统的应用程序,我无论是这里提到绕过权限将不起作用:<一href="http://stackoverflow.com/questions/11288788/usb-open-accessory-permissions-through-a-service-in-android">USB通过Android的服务开放的配件权限

This question: Android USB Permissions Dialog never appears had the opposite problem, but the solution won't work for me.
Making the app a System app and bypassing permissions won't work for me either as mentioned here: USB open accessory permissions through a service in android

任何帮助是极大AP preciated

Any help is greatly appreciated

推荐答案

我有同样的问题,在使用该设备写这个活动你的Andr​​oidManifest.xml:

I have the same problem, in your AndroidManifest.xml in the Activity that use the Device write this:

<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/device_filter" />

您还可以在你的XML资源,创建一个过滤器文件,如RES / XML / device_filter:

You also have to create a filter file in your xml resources, eg res/xml/device_filter:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
    <usb-device vendor-id="26214" product-id="26214" />
    </resources>

厂商ID和产品ID在这里有十进制给予 - 上述两个VID和PID是0x0123。你看到的<一个href="http://stackoverflow.com/questions/12388914/usb-device-access-pop-up-su$p$pssion/15151075#15151075">USB设备访问弹出苏pression?

您不能调用mManager.requestPermission(设备,mPermissionIntent),所以你必须直接调用mManager.openDevice(mDevice);并且可以正常显示许可弹出​​消息,通讯,而不需要。

you must not call mManager.requestPermission(device, mPermissionIntent), so you have to directly call mManager.openDevice(mDevice); and you can communicate normally without the need appear permission pop-up message.

问候, 塞缪尔Reque samo_reque@hotmail.com

Regards, Samuel Reque samo_reque@hotmail.com

这篇关于Android的USB设备的许可和意图过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆