-
Notifications
You must be signed in to change notification settings - Fork 408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Android Cannot Open device (hid_open) #178
Comments
The best what I can suggest right now - try to debug native calls (e.g. to libusb) and check its error-codes, to understand why the device cannot be opened. |
Does your app have the correct permission filter in its AndroidManifest.xml and your code have the correct PendingIntent sent to |
For the permission I'm pretty sure they are ask correctly as I have an Android popup asking me if I want to grant permission to the app to use the USB. Should I grant permission to hidapi instead of grant it to my app ? (I don't know if it's possible and how to do it). |
Are you trying to open the hid device using its linux device path instead of its device id? Its an easy mistake I made multiple time. |
@tuxun I'm non sure to understand what you mean by device id as I'm using hid_open to find the path. hid.c (line 697)
|
Hi, From this post: #137 (comment) Hoping it will help you |
Hi,
that why I'm trying to do but in Does any one know or have an idea why Line 906 in ca1a2d6
|
"On Android hidapi is using libusb backend, and it doesn't operate with file-paths, but instead with USB entities, like "bus_number:device_address:interface_number", which makes a path, and it is a correct representation." I think the answer is in there: hid_open_path char *dev_path = make_path(usb_dev, intf_desc->bInterfaceNumber);
if (!strcmp(dev_path, path)) {
/* Matched Paths. Open this device */
/* OPEN HERE */
res = libusb_open(usb_dev, &dev->device_handle);
if (res < 0) {
LOG("can't open device\n");
free(dev_path);
break;
} I would try something like hid_open("bus_number:device_address:interface_number"); as stated in the other answer i linked above. |
As was pointed by @DavEat,
This part is used only to identify corresponding
I wouldn't recommend anything like that.
Well that's a good question. if I'd need to guess, I'd say it either matches a wrong libusb device (on Android), or some kind of permissions issues |
I'm having the same problem. |
libusb/libusb#830 |
For Android users with libusb backend of HIDAPI, please check out libusb/libusb#830 which should work on unrooted Android device. Yet the other new pull-request which may be even better is libusb/libusb#874 which is supposed to work with unrooted Android device "without user provided Java code". |
Right, so I actually have a project that is using HIDAPI on Android un un-rooted device. Android normally doesn't allow opening Essentially, to open a USB/HID device on Android, one must have some Java (or Jni) code that:
So far I'm the only known to me user of |
My last message full describes the only possible workaround as of right now. |
Added the above comments to Wiki. |
Hi,
I'm using .so libs of hidapi and libusb compile with linux for android
I have integrated those lib in a c++ project to make an interface to be able to call function in Java
(e.g. JNIEXPORT jint JNICALL Java_com_company_project_class_Enumerate(char* string, int length) //hid_enumerate
JNIEXPORT jint JNICALL Java_com_company_project_class_Open() //hid_open
(for now the vendorId and the productId are hard coded in the c++))
With hid_enumerate I have succeed to get some data from the devices such as the path or the vendorId
But if I try to use hid_open or hid_open_path it's always returning a nullptr hid_device*.
I should have set up my permission correctly (when I connect my hid device the phone ask me if I want to use the app I made with the usb device I just connect).
I also try to integrate it in Unity3d and I have the exact same behaviors.
Any help would be much appreciate since I'm completely block ATM.
The text was updated successfully, but these errors were encountered: