I want to use android in industry,
I can connect to Profilic and Ftdi USB to Serial chips with slickdevlabs.com library without any problem.
The application has a service and it starts on boot,connect to the usb serial port and do the other things.
my problem is that the host device does not have any interaction with user,
so when the android asks
Allow the app "MyAPP" to access the USB device ? [checkmark]Use by default for this USB device Cancel OK there is no person to click on ok.
even when I check the use by default... checkbox,If I reinsert the USB ,or reboot the host device, it asks again on next boot.
and the answer is mentioned in this link : bypass android usb host permission confirmation dialog but the codes are for : "Note that interfaces of these classes may change depending on the version of Android. In my case the version is 4.0.3. So if you have another version of Android and this code doesn't work you will have to check the source code for your particular version of OS."
so i need the same codes for android 5.1 please
Have you tried using an intent-filter in the Manifest as described here: https://developer.android.com/guide/topics/connectivity/usb/host.html#using-intents
I had a similar issue - it seems like if you programmatically request a USB permission, it will ignore the ticked checkbox and ask you every time again.
Edit: If you are having issues because of the service, you might want to read this too: https://stackoverflow.com/a/15151075/3540885
It's been a while since you asked this... but in case it can help someone here is my answer.
The accepted answer in the initial question states:
So you should get the files you need directly from the android source code. You can download the source code relative to your version or browse directly from the repo.
The IUsbManager interface you are searching for is normally under: /frameworks/base/android-branch-name/core/java/android/hardware/usb. As for the Service Manager it can be found under: /frameworks/base/android-branch-name/core/java/android/os/
I didn't post the code since I suppose you're not searching for it anymore after 2 years+ :)
=== EDIT ===
As asked, here is the code. I made it work for version 6.0.0, but I think functions calls are the same as 5.1. To be verified.
First, here is the android project structure you will get:
Create the interface IUsbManager.java in android.harware.usb:
Then create the java class ServiceManager.java in android.os:
Once this is done, don't forget to add the android.permission.MANAGE_USB in you AndroidManifest.
Then you can use those function calls:
There's a check on whether your application is a system application and if it has the correct permission, otherwise it would not work.
Also be aware that your vendor id is not in hexadecimal but in decimal.