java - libusb_open_device_with_vid_pid failed when trying to access USB device -


i trying usb device connect android 5.1.1 device. had been using regular libusb kitkat, lollipop has increased security , no longer works.

this documented, requiring root set selinux level. not want have root device usb device connect it.

having looked around, came across this answer , have tried this libusb fork, getting new error

libusb_open_device_with_vid_pid (29c2) failed. failed setup usb usb_setup: -1 

i have not changed of code, library.

is still permission issue, or there i'm missing make work?

the following steps can used solve issues mentioned.

the process of mounting device usb mass storage inconsistent across devices , manufacturer-specific. devices nexus s offer "turn on usb storage" when connect device desktop via usb cable. other devices galaxy s3 require app launch device mass storage. either way, android devices typically offer such feature, , you’ll have create file matches device's manufacturer specification.

you need add application's manifest file before working usb host apis:

  • because not android-powered devices guaranteed support usb host apis, include element declares application uses android.hardware.usb.host feature.
  • if want application notified of attached usb device, specify , element pair android.hardware.usb.action.usb_device_attached intent in main activity.

add usb_device_attached manisfest file:

<manifest ...>     <uses-feature android:name="android.hardware.usb.host" />     <uses-sdk android:minsdkversion="12" />     ...     <application>         <activity ...>             ...             <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> 

to app discover particular usb device can use intent filter:

<activity ...>     ...     <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> 

you have specify device , vendor id:

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

this should enough deal usb host connection. call usb:

int libusb_call libusb_open2(libusb_device *dev, libusb_device_handle **handle, int fd); 

use descriptor open connection usb device - e.g.:

usbmanager myusbmanager = (usbmanager)  getsystemservice(context.usb_service); usbaccessory myusbaccessory = (myusbmanager.getaccessorylist())[0]; parcelfiledescriptor pfd = myusbmanager.openaccessory(myusbaccessory); filedescriptor filedescriptor = pfd.getfiledescriptor(); fileinputstream myfileinputstream = new fileinputstream(filedescriptor); fileoutputstream myfileoutputstream = new fileoutputstream(filedescriptor); 

if still have problems selinux level, here have edits can use make program run smoothly:

// default.prop ro.secure=1              -----------------> ro.secure=0 ro.adb.secure=1        -----------------> ro.adb.secure=0  //init.rc setsebool debugfs 1   --------> setsebool debugfs 0 setenforce 0 setprop selinux.reload_policy 1  ------->  setprop selinux.reload_policy 0  // init.target.rc setprop selinux.reload_policy 1   ----->  setprop selinux.reload_policy 0 

as selinux default set enforce highest security, , want grant client access android device through usb.

enter image description here

depending on android make , model, try unplugging usb cable connecting device , desktop, , plug in. should prompted "turn on usb" storage. if case, go ahead , try browsing settings → more... on android, , usb mass storage option.

http://www.pocketables.com/images/old/6a00d83451c9ec69e201675f40c44a970b-500wi.png

alternatively usb mass storage process recommended device manufacturer. when turn on usb storage , device let’s know apps stop, go ahead , ok that. move on desktop computer , browse usb mass storage medium, called no name if you’ve not renamed it. click on mass storage device, , right there in foot folder, find file called data.tsv .

enter image description here

you can check data.tsv opening in favorite text editor. you’ll find 2 columns there neatly separated tab; in each row, you’ll find pair of integer values. sufficient our project. more complex data projects typically require unique identifier each row, row in 1 table point specific record in another.

enter image description here

according development environment, have tune settings accordingly. if developing on windows, follow usb driver installation instructions available. if developing on linux, follow instructions setting up device development.

enter image description here

in addition, worth mention many released android-powered devices capable of acting usb device , cannot initiate connections external usb devices. android open accessory (aoa) support overcomes limitation , allows build accessories can interact assortment of android-powered devices allowing accessory initiate connection. example of common use of android open accessory can found in project: record , play audio using usb host mode - of course requires usb mode , running.

enter image description here

putting android communicate through usb arduino microcontrolers type of implementation showed become successful recently, allows extend android capabilities integrating additional features through multi-device solution approach. typical arduino sketch allow device communication android usb this:

// usb host libraries #include <max3421e.h> #include <usb.h> // aoa library #include <androidaccessory.h>  void setup(); void loop();  void setup() {   // start serial debugging     serial.begin(115200);     serial.print("\r\nadk has run setup().");     serial.println("ready start usb communication..."); }  void loop() {   // example - read voltage sensor     uint16_t val;     val = analogread(temp_sensor); // or sort of input     serial.println(val,hex);     serial.write(val);     // delay 100 milliseconds.     delay(100); } 

all arduino projects must have setup() , loop() method declared otherwise android not communicate properly.

also remember list of minimum requirements needed use aoa:

  • an aoa-compatible android device. test compatibility before trying example, please refer “supported android devices” section links microchip aoa demonstration apps available on google play.
  • a compatible microcontroller board. arduino mega adk easy option if unsure.

enter image description here

possibilities of android devices using usb amazing, , demand innovative apps capable of taking full advantage such features set grow remarkably.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -