高通android设备libusb,Android 用 libusb 操作 USB 设备,无须 root

这篇博客介绍了如何在Android设备上使用libusb通过USB Host API获取FileDescriptor,并实现libusb_open_fd函数,以便在不需root权限的情况下操作USB设备。
摘要由CSDN通过智能技术生成

获取 FileDescriptor

// get FileDescriptor by Android USB Host API

UsbManager manager = (UsbManager) mContext.getSystemService(Context.USB_SERVICE);

final String ACTION_USB_PERMISSION = "com.android.example.USB_PERMISSION";

HashMap deviceList = manager.getDeviceList();

Iterator deviceIterator = deviceList.values().iterator();

PendingIntent mPermissionIntent = PendingIntent.getBroadcast(mContext, 0,

new Intent(ACTION_USB_PERMISSION), 0);

IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);

mContext.registerReceiver(mUsbReceiver, filter);

int fd = -1;

while(deviceIterator.hasNext()){

UsbDevice device = deviceIterator.next();

Log.i(TAG, device.getDeviceName() + " " + Integer.toHexString(device.getVendorId()) +

" " + Integer.toHexString(device.ge

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值