I've a system with an Android Tablet + an embedded board implementing AOA Protocol.
All works fine, embedded board when connected to Android device send ACCESSORY_START command and Android enters in AOA mode. Then normal flow between two works fine too.
Now I've a question:
There is a way from embedded target to disable AOA mode without physically remove USB cable ?
A sort of ACCESSORY_STOP, so my Android target regain usual PID:VID instead of PID:VID for AOA mode ?
Or there is a way to do that programmatically with Android code ?
If you want to close the accessory on app exit (without unplugging it), call System.exit(0) in Activity onDestroy(). This kills all app threads, including the accessory read thread which blocks the input stream. The accessory can then be reopened without re-plugging.
This is a partial answer to your question (just to make it clear for the watchful pedants diligently monitoring other people's business). But it's useful, because at least you can exit your app and then reconnect the accessory again without unplugging.
And yes, the problem is still with us in 2017., although it was documented ages ago.
I am dealing with the same issue in an embedded project. In the case of Android devices, I believe that power needs to be removed from the USB pins in order to cause a reconnection.
A USB reset at the data level from the host is not enough. I have personally tested resetting the bus, but the device simply reconnects as accesory mode.
If the android accessory device has the ability to power the controller on or off, then a physical USB reconnection can be simulated. In the case of my embedded platform this is performed by using echo 0 or echo 1 into /sys/class/gpio/123/value where 123 is the pin number defined in a header file in the linux kernel sources. This pin number must exported to user space, and must be aligned with the schematic of the embedded project to the pin that controls the powering of the controller which may be called PWR_EN or ENABLE.
Good luck!
Related
My device is not showing up in eclipse [Note that this is not a dublicate, read further].
I have booted my PC into safe mode, and I guess there's no options or I may setting or service enabled for usb adb/debugging.For instance, sound is also disabled in safe mode, but there is a way of getting it on safe mode by adding the service to
"_hklm\system\currnetcontrolset\control\safeboot\_",maybe.
Please tell me which services to put here or a way to detect my device.
I'm running Windows 7 Home Basic, Galaxy Fit GTS-5670, 2.3.6
My device is properly recognized in normal boot, but not in Safe Boot/Mode.
Basically safe mode is used only for the OS to load when there is a system-critical problem that interferes with the normal operation of Windows( removal of viruses ,worms etc. are done in safe mode).In safe mode your Operating System runs in isolation mode i.e. it will not load all the functions but only some to repair and perform the evaluation of your system.
Due to which most of the device drivers will not be loaded .So the eclipse will not display you the device as the USB debug device driver is not loaded by the operating system(windows 7 in this case).
I have a measurement device which sends data as keyboard wedge when connected to a PC. I would like to be able to use it to input data into an Android phone or tablet through the USB port.
Anyone have an an idea if Android device USB port can be used in that way?
Only some Android devices support USB host mode, but those that do would typically recognize a keyboard as a keyboard and use it as such. An adapter cable is typically required.
One problem this might present is that if your app goes to the background, you would probably lose the keyboard input as it would instead go to whatever is in the foreground. The Android security model, if still intact, would prevent snooping on keyboard input when not in the foreground.
(They often support mice too - kind of funny to see a mouse cursor appear on your phone)
Depending on your particular model of Android device, you may be able to use this adapter, or one like it, to connect a keyboard via Android's support for USB On-The-Go
I like USB debugging on Android as it is faster than Emulator. I know I can use my keyboard in emulator but while debugging I want to use my computer keyboard (plugged to computer) instead of devices keyboard for making my input more faster. Is that possible?
Share KM is a free app that lets you use your PC's keyboard and mouse to control your Android. Connection can be made over USB, WiFi, or Bluetooth.
It works a lot like adding an additional monitor to your computer – move your mouse to the edge of your screen and the cursor moves to the Android.
I found a possibility via "adb tools". Connect your phone to the computer via usb cable and start adb at the computer terminal (e.g. Ubuntu)
adb shell input keyboard text Hello
or
adb shell input [<source>] <command> [<arg>...]
This will give you the possibility to send text/keystrokes via computer/laptop keyboard to your smartphone.
Note: your input will be sent through two shells (computer and android device), so you'd have to "double escape" even spaces. To avoid that, you may e.g. type
adb shell
input keyboard 'any text you like, including shell-sensitive characters'
the second line is input on your android device in adb shell
Tested on Ubuntu 14.04 LTS and Samsung Galaxy S3 with CyanogenMod.
Confirmed on Ubuntu 18.04 LTS and Moto G2 with Lineage OS
It sounds like you want to use your PC's keyboard via some software on the PC rather than use a separate USB keyboard connected to the Android device.
This actually is possible, but the details are device specific. You would need to send key events via adb, but you'd need to determine the implementation-specific translation of characters to event codes, and even the event channel number. There are likely open source projects out there for doing this, and you'd be better off starting with one of those than trying to develop it from scratch.
As for using a separate USB keyboard, as mentioned in comments this is a possibility on some more recent devices (typically you need an adapter cable with the ID pin grounded) but introduces the issue of not being able to use USB for ADB as well as a keyboard at the same time. One possible workaround would be to put ADB into TCP/wireless mode, unplug the computer and plug in the keyboard. A simpler approach could be to use a bluetooth keyboard.
Note that either the USB or bluetooth keyboard, and likely also the key event method, will cause the on-screen keyboard to pop up. People trying to use devices with external keyboards find this annoying and tend to install zero-height on screen keyboards; however, if you are testing what an actual user will do, then having the keyboard pop up will give a more realistic impression of the end-user experience (though of course the amount of screen real estate left after the keyboard varies from device to device).
Plug your keyboard directly into Android USB OTG port and it will work. Most of recent Android devices do support USB host mode apart very few models that have this feature intentionally removed (Google). There is also a good our guestion about this.
With my Google Galaxy Nexus and Lenovo tablet, even mouse works (mouse pointer appears). You probably can use USB switch that allows to share the keyboard between two computers. Mind also that you need USB OTG and not USB device converter (there are some USB converters that fit into micro USB OTG port nicely but are for USB devices only).
Of course, ADB cannot use the USB port if it is already taken by the keyboard. Hence you need to use wireless for ADB.
This proposal does not match fully your initial idea but seems matching the goal you are aiming to achieve (debug Android app directly on device using your keyboard).
I'm writing an application which is supposed to dump data on the SD card and then another application on a pc which should read the data when the device is connected to the pc (in disc drive mode).
On my HTC Legend there is a dialog to choose between: Charge only, HTC Sync, Disk drive..
Is there a possibility to set the mode with which the device is connecting to the pc
or at least an intent to ask the user to switch the mode?
I haven't found a way of setting the mode programmatically, but I believe you can bring up the settings menu programmatically by invoking the same activity that the system invokes from the notification area. Unfortunately this appears to be manufacturer-specific: on my phone it is com.htc.android.psclient.SwitchUsbSettings.
On HTC devices, open the ConnectToPC service (whilst USB is not plugged in) in Manage Apps (ICS - probably applies to Gingerbread too; don't remember), and hit Clear Data. Then, plug the USB back again, and you should have the option to "Don't ask again" available. Select your desired mode, check the box, and accept.
CompanionLink does this when you request a USB sync in their android app: it flushes data to SD, then exports the SD as storage (a "disk drive") on the USB, then waits for the user to manually signal the android app when the PC is finished using the SD, and then undoes the SD export to USB again. Though the CompanionLink app can be very frustrating to use, at least this part of it is (largely) reliable.
Unfortunately I don't know the technical details, may well need to figure them out myself one of these months. If you can't get any traction with android docs, perhaps you could study what CompanionLink does on android to implement this. The sequence I describe above is when it is configured to sync over USB against a (PC-based) Palm Desktop.
As an aside, it appears that the reason for this highly-convoluted process is that the SD card's FS is accessed directly and at least the presently-used card FAT FS can only support a single client: the phone itself or USB. imo it would be extremely helpful if concurrent shared access to the SD were possible, but this would likely require deep android changes.
For anyone having this issue with an HTC One M8, this is a bit off the wall, but makes the point to think outside the box. A USB connection resulted in the device charging, that was it.
The solution was the combination of a different USB cable, uninstalling an application called Battery Doctor (which apparently likes to manage everything around your battery), AND USB Network Setting - turn ON Smart Network Sharing...Seemingly unrelated...but this combination got my connected with MobileGo for Android to manage and back up files,contacts and settings.
Hope this helps someone.
Yes .In Android there is a way to change the behaviour of the devices`s USB mode when the device is connected with the PC.
I used a Motorola Milestone[running 2.1] and i was able to switch between the following modes :
PC Suite[developed by Motorola],MemoryCardAccess and Charge alone.
If you need to access phone memory I think you should turn ON "USB Debugging Mode " in your device.Am not sure about it though,I feel it may be handy !!
Is it possible to access the USB port on Android phones? (Droid X for example)
Here is my usage case:
Have a USB device attached to the Android phone. The phone listens for data on this USB device. (The USB device is connected to a USB->RS-232 converter that has I/O attached to it)
This would be slick if possible. Does anyone know if this is possible?
Would be slick, yup. Not possible though. There's a feature request for it: http://code.google.com/p/android/issues/detail?id=738
Actually it is possible on a lot of the phones if you are able to install a new kernel with a USB host driver and rig up a custom cabling scheme to provide usb bus power to the device as the phone won't. A few phones even shipped with this capability already live.
I don't know if the Droid X specifically ships with this already, can have it added (if you are able to flash kernels), could have it added but no one has written the host driver yet, or is missing the hardware capability.
You also would need to enable the appropriate usb serial converter device driver (identified by experimenting with the device on a desktop linux box), but that's probably already in the kernel sources and just needs to be selected in the config. You may also need to create a device file for the /dev/ttyUSB0 or whatever and give it permissions appropriate to the application that wants to access it. (This requires root, but if you can reflash the kernel, you can get root)
If you want to pursue this, search the android kernel google group for posts about USB host mode.
One serious downside to putting the USB into host mode is that you loose the adb interface into the phone, which makes working on your projects hard. You'll probably need to either build an adapter for the low voltage debug serial port if there is one (as on G1, mytouch, etc) so you can get a console shell (or just use that instead of USB to talk to your peripheral) or at a minimum set up an ssh and sftp server on the wifi.
Since you want serial anyway, another option people have used is to get a bluetooth-to-serial module from an outfit such as sparkfun.
A bluetooth to serial adapter might solv your problems.
You can find one at https://www.sparkfun.com/products/582. Boards from other companies are also available for example on ebay.