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
Related
I have an "MINIX NEO X7 mini" Android device. There is installed application eHomeMediaCenter. It is a DLNA server. Then I launch RKRemoteControl application on my Android smartphone, select eHomeMediaCenter and see mouse cursor on my Minix. And then I can move and click. But what protocol is used for that? And why in eHomeMediaCenter? Please, give me some info about that.
Mouse and keyboard functions in the Minix Neo -- and probably Android devices in general -- builds on the desktop Linux keyboard and mouse support, specifically on /dev/hidraw -- the Human Input Drivers. See enter link description here for more info. A variety of external mice, keyboards or 'air mouse/keyboards' can be connected to the Minix Neo x5/x7 by USB, Bluetooth or other wired or wireless connection and feed mouse events of keyboard events to the normal Linux HID processing that Java -- and the Android apps consume.
I use this air mouse/keyboard with the Neo x5. (Air mouse means that the device is not placed on a desk, but accelerometers in the device allow you to wave the thing around to produce mouse movement.) What ever (perhaps proprietary) protocol is used between the device and the device driver is converted (in the device driver) to a data stream that emulates the signals that a conventional, old style, wired mouse or keyboard produced. Some devices use a generic HID device driver that is used for a serial (ie old RS-232, TTY, phone modem) device.
go through below link
http://support.aboway.com.tw/products/android/A18/TV%20stick%20mobile%20remote/RKRemoteControlGeneralCastV2.0.3/doc/index.html?com/rockchip/remotecontrol/common/DeviceCache.DeviceChangeListener.html
u will get code to implement
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!
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).
Ok so i bought Chinese tablet and chinese Keyboard which drains my tab battery v.fast, so
i am thinking to create an app to enable and disable physical keyboard, can any one help me for how i can target physical keyboard in codings, or is there any other possible way.
EDIT: by Disable i mean no interaction in any sense with physical keyboard, or say disable usb port, what you'll suggest
I also have ROM toolbox, which also allows me to play with some of the build properties so if u can help me in this way than i will be very thankful b/c it will save me alot time.
Android: 4.0.3
keyboards connects with usb cable.
anyway Thanks in Advance
Anyway i would like to share my solution,
I enabled Pin Lock and it turns android into sleep mode, so after a little time my physical keyboard gets disabled automatically, (capslock light stops responding).
;)
I am doing research delving into the Android ADK. So far, my program gets the list of attached devices from the USBManager class and displays basic information about them. The USB Host mode works well and recognizes multiple connected devices even when they are two or three USB hubs away. However, the list never contains USB mice or USB keyboards, even though these devices are recognized by the system and used for input (typing into a text area, etc.). It seems that the system grabs these and doesn't present them to the ADK framework.
Is this functionality intentional? Is there any way to get access to these HID devices? As far as I know, the only to ways to get access to USB devices in Android host mode are the USB Manager and intent filters. Another poster came to the conclusion that neither allows access to HID devices.
Thanks in advance for any information or comments about this topic; I'd really like to get access to mice/keyboards so I can practice USB communication with simple devices.
What version are you testing on? 2.3.4 or 3.1?
Did you try using com.android.future.usb or android.hardware.usb?
If you can already use the HID device for input, it' working as a input device(keyboard or mouse) and you don't need to access it as a USB device.
You can simply catch the input from the device via listeners such as OnKeyListener.
If you want to check the input devices, see Can't see mouse and keyboard device with usbManager android.