请问android usb host模式 中需要什么权限

lgxing 2012-04-16 07:07:10
平台Android 4.0.3
我在使用UsbManager获得设备列表后,在打开设备时出错:
UsbDeviceConnection udc = mManager.openDevice(device);//出错,缺少权限
udc为null
请问需要什么权限,是在程序中加还是系统中加?
...全文
2668 28 打赏 收藏 转发到动态 举报
写回复
用AI写文章
28 条回复
切换为时间正序
请发表友善的回复…
发表回复
haiming80 2014-10-17
  • 打赏
  • 举报
回复
((UsbManager)getSystemService(Context.USB_SERVICE)).requestPermission(dev, pi); 上面是关键地方,余下的你自己研究吧
伟鸿IT 2013-07-14
  • 打赏
  • 举报
回复
楼主是否已经解决了次问题,望指点,我也一直找不到原因,希望楼主发帖啊! 楼主QQ是多少?我的是747061457, 很想解决这个问题。。。。。。。。。
Seh_Cracker 2013-07-03
  • 打赏
  • 举报
回复
这么长时间了不晓得楼主解决没有,解决的话求教育呀,qq:457991
lgxing 2012-09-06
  • 打赏
  • 举报
回复
不是手机,所有3.1版本以上的,愿意开放usb接口支持的
否则需要自己将android.hardware.usb.host这个feature加进去
sos995 2012-08-30
  • 打赏
  • 举报
回复
急问:楼主定制的机器是手机吗,可以定制手机吗?
现在有哪款android手机也支持啊
请回复啊
lgxing 2012-06-28
  • 打赏
  • 举报
回复
兄弟还没有搞定啊?就是那么xml文件,只要放到那里就可以了,你的设备具体为什么不行,这个就不知道了
limitemp 2012-06-27
  • 打赏
  • 举报
回复
mManager.openDevice(device);这个打开设备出错,权限不足楼主怎么解决的啊?那个XML我平板里有啊
lgxing 2012-05-10
  • 打赏
  • 举报
回复
如果在AndroidManifest.xml中增加了红色部分,那么指定类型的设备就自动获得权限了
否则,在操作之前需要requestPermission获得权限
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="lgx.MyTest"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="12" />
<uses-feature android:name="android.hardware.usb.host" android:required="true"/><!-- android:required="true" -->

<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".MyTest"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</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/device_filter" />
</activity>
</application>

</manifest>
limitemp 2012-05-10
  • 打赏
  • 举报
回复
好像连接建立之前如果是列举的方式获得设备要先申请
mUsbManager.requestPermission(device, mPermissionIntent);
limitemp 2012-05-10
  • 打赏
  • 举报
回复
那你权限的问题解决了吗?
limitemp 2012-05-10
  • 打赏
  • 举报
回复
[Quote=引用 17 楼 的回复:]

我们自己定制的机器,android4.0.3
将android.hardware.usb.host.xml文件push到/system/etc/permissions目录下
然后关机,重新启动ok
[/Quote]
额,那谢谢了
lgxing 2012-05-10
  • 打赏
  • 举报
回复
我们自己定制的机器,android4.0.3
将android.hardware.usb.host.xml文件push到/system/etc/permissions目录下
然后关机,重新启动ok

limitemp 2012-05-10
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 的回复:]

我的机器是在/system/etc/permissions下
[/Quote]
DX我试了还是不行啊?
limitemp 2012-05-10
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 的回复:]

我的机器是在/system/etc/permissions下
[/Quote]
是什么型号的机器呢?
lgxing 2012-05-10
  • 打赏
  • 举报
回复
我的机器是在/system/etc/permissions下
lgxing 2012-05-09
  • 打赏
  • 举报
回复
在设备的权限目录中增加文件android.hardware.usb.host.xml,这样就可以获得设备列表了
内容如下:
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2011 The Android Open Source Project

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<!-- This is the standard feature indicating that the device can communicate
with USB devices as the USB host. -->
<permissions>
<feature name="android.hardware.usb.host" />
</permissions>
duheping001 2012-05-09
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 limitemp 的回复:]

获取的设备列表一直是空的,什么原因啊
[/Quote]同求啊,LZ用的是什么手机啊,我的设备列表也一直是空的,不知道是为什么?
redjianguo 2012-05-09
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 的回复:]
引用 6 楼 的回复:

在设备的权限目录中增加文件android.hardware.usb.host.xml,这样就可以获得设备列表了
内容如下:
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2011 The Android Open Source Project

Licensed under the Apa……
[/Quote]
如何获得设备列表,我的设备列表一直是空!权限目录在哪里 ?
hrsqs110 2012-05-09
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 的回复:]
在设备的权限目录中增加文件android.hardware.usb.host.xml,这样就可以获得设备列表了
内容如下:
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2011 The Android Open Source Project

Licensed under the Apache License, ……
[/Quote]
求楼主用的是什么设备测试。。。权限目录在哪?
huhuhu121212 2012-05-09
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 的回复:]

在设备的权限目录中增加文件android.hardware.usb.host.xml,这样就可以获得设备列表了
内容如下:
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2011 The Android Open Source Project

Licensed under the Apache Licen……
[/Quote]

大侠求教育,说具体点,我的q:850460714
加载更多回复(8)

80,363

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧