How to detect USB port on android? - android

I'm developing printer application based on Android phonegap.Now i hard coded the data and sent it to the printer.It's working fine.But my requirement is data will come on from the taxi meter via USB cable.How can i detect that data coming port?

What you're most likely looking for is the Android Open Accessory Development Kit. Keep in mind the following:
Note: Accessory mode is ultimately dependent on the device's hardware
and not all devices will support accessory mode. Devices that support
accessory mode can be filtered using a <uses-feature> element in
your corresponding application's Android manifest. For more
information, see the USB
Accessory
Developer Guide.
Another thing to be aware of is that if your other device does not support Accessory mode, you can either make it support accessory mode (you haven't mentioned if this a homebrew or commercial device), or root your Android device and then pretty much anything is possible.

Related

Is it possible to access an android accessory through WebUSB?

I have a custom hardware, that works as an android accessory connected to a phone through USB. I managed to communicate with it through a native android app. I'd like to know if it's possible to communicate with it through the WebUSB API.
So far I just tried listing the available devices with requestDevice() using an empty filter but my device doesn't show up in the list. The site is served through https so that's not the issue and other devices that work with otg show up.
I haven't managed to found anything in docs regarding support for android accessories.
WebUSB is a wrapper around the Android USB Host API, which supports communicating with peripherals connected in client mode. The Android USB Accessory API requires the peripheral instead to be in host mode (with the Android device being the client) and provides a very different interface for reading and writing data.
This interface looks more like what is provided by the Serial API so it may make sense to expose accessories through that API instead. This is an area to research further. I have filed issue 987271 in the Chromium repository to track this exploration.

How can I use adk Library

I'm new to android and trying to learn hardware interaction in android
have to root to install driver of hardware.
can I use adk library for custom hardware development.
As shown here,
if using accessory mode, then accessory must power the bus.
But as specified here,
accessory can be anything as keyboard too.
So i got confused: how can a keyboard power the bus?
Please help me out.
You misinterpreted those sites.
When you want to connect something like a keyboard, your android device must be in host mode. It will provide power to the keyboard.
The android device will only attempt to draw power from the other device if the other usb device acts as host.
In USB host mode, the Android-powered device acts as the host.
Examples of devices include digital cameras, keyboards, mice, and game
controllers.

USB code for Android 2.3.4

I want to use usb in my application to retrieve data from my computer (present in text files) to android mobile and read it... what are the neccessities in terms of hardware and helpful links for the usb code...
Recently google launched USB accessory for android 2.3 ... it have classes UsbManager, UsbAccessory etc... i want to use that ... how can it be used.??
Usually the opposite of this is observed, where the android mobile projects itself as a usb device (client) , The USB host controller driver on the computer recognizes the device and handles future USB requests from your client. This is just the hardware layer, mind you. Since the USB protocol has become so ubiquitous, the computer actually stores multiple families of drivers both at the kernel layer and user space to be able to handle the variety of requests and their user space interpretations.
Since android mobiles are primarily linux-based devices, to achieve your end you will need to integrate these USB host-based driver families to your device's kernel / ROM. You will need to create a custom ROM (someone else asked this question here). This link provides you a list of drivers corresponding to specific hardware families.
Additionally, you will need to set up necessary programs on your computer that allows it to project itself as a USB client.
If you use linux on the computer too, this article might help you to start.

Gameboy-like keys and D-Pad for Android

I wanted to make an RPG for Android 2.3 Mobile Phone and thought that the good old Gameboy had the perfect format for such games. So I want to build a "Case" with a D-Pad and a few keys and connect them with the Android Device over USB. I don't want Bluetooth, because it needs to much energy. I thought about giving the Case its own Battery Cell and maybe loading the Android Device with it. So my Question is:
How can I access the Keys of this Case from the Android Device?
You might consider the Android Open Accessory Development Kit.
Even if you don't want to buy the ADK, the above link has information that will be useful to you in developing an interface to your accessory. In particular, the section on implementing the accessory protocol and the following section on how the ADK implements the protocol should prove informative. In addition, you'll probably want to look at the USB Accessory link which contains a section concerning communication with an accessory.
You can use USB on devices that have a host USB port unfortunately, not many devices have this. Your other options are bluetooth or wifi both can be accomplished in a multitude of ways. If you Google Arduino + Android I believe you will find examples of people connecting hardware to Android devices via Arduino. This is not the only way to do it, just an example of one way you could do it.
Android USB documentation
http://developer.android.com/guide/topics/usb/index.html
EDIT
You, could I suppose, use Arduino as the USB host also and use accessory mode on the Android end. In any case this none of these options are incredibly straightforward and you will need to do a lot of research to accomplish what you are envisioning.

Android USB host-to-serial connection?

Apparently with Android 2.3.4 and 3.1 one can now access USB accessories.
I have a Ardupilot Mega (based on Arduino) board with a USB cable connected to my laptop, and I can connect to it using a simple serial communications program over COM7 and 115,200 baud. This allows me into the command-line interface, and I can issue commands and get logs.
Is it possible to write an Android app that will communicate over USB to my Ardupilot Mega board?
I've seen many similar threads, but most of them were pre-USB host.
usb-serial-for-android is my open source library written for exactly this need. It supports FTDI and CDC-ACM usb serial devices using Android's USB host support; no root or ADK necessary. It can talk most Arduinos.
The project is still in its early days, but the basic support has worked well enough for several projects. There is also a discussion list where you can get help.
Unfortunately the library from mik3y's answer (see here: mik3y/usb-serial-for-android) seems to be long dead. It has many problems and waiting pull requests. Also the LGPL licence prevents anybody to fork it and maintain it.
But don't lose your hope, there's a working replacement and it's under the MIT licence. felHR85/UsbSerial.
EDIT: I found a maintained fork of mik3y's library. But the licence or readme is not updated, so I suppose the owner doesn't have a connection to mik3y and simply took it and improved it. I hope he won't get into any trouble because of the licence, because we need this library. See kai-morich/usb-serial-for-android
EDIT2: It seems that all of these libraries are maintained again, mik3y joined forces with kai-morich and they're working together now.
EDIT3: mik3y/usb-serial-for-android is under MIT license now. And still maintained in 2022.
Maybe. Check out the Android Open Accessories announcement on the Android Developers Blog. The Arduino Mega ADK is compatible. Not sure about the Ardupilot Mega.
From their page:
The Android 3.1 platform (also backported to Android 2.3.4) introduces
Android Open Accessory support, which allows external USB hardware (an
Android USB accessory) to interact with an Android-powered device in a
special "accessory" mode. When an Android-powered powered device is in
accessory mode, the connected accessory acts as the USB host (powers
the bus and enumerates devices) and the Android-powered device acts as
the USB device. Android USB accessories are specifically designed to
attach to Android-powered devices and adhere to a simple protocol
(Android accessory protocol) that allows them to detect
Android-powered devices that support accessory mode. Accessories must
also provide 500mA at 5V for charging power. Many previously released
Android-powered devices are only capable of acting as a USB device and
cannot initiate connections with external USB devices. Android Open
Accessory support overcomes this limitation and allows you to build
accessories that can interact with an assortment of Android-powered
devices by allowing the accessory to initiate the connection.
Note: Accessory mode is ultimately dependent on the device's hardware
and not all devices will support accessory mode. Devices that support
accessory mode can be filtered using a "uses-feature" element in your
corresponding application's Android manifest. For more information,
see the USB Accessory Developer Guide.
The following list of distributers are currently producing Android
Open Accessory compatible development boards:
The Arduino Store provides the Arduino Mega ADK (in EU nations or
non-EU nations) that is based on the ATmega2560 and supports the ADK
firmware. DIY Drones provides an Arduino-compatible board geared
towards RC (radio controlled) and UAV (unmanned aerial vehicle)
enthusiasts. Microchip provides a PIC based USB microcontroller board.
Modern Device provides an Arduino-compatible board that supports the
ADK firmware. RT Corp provides an Arduino-compatible board based on
the Android ADK board design. Seeed Studio provides an
Arduino-compatible board that supports the ADK firmware. SparkFun's
IOIO board now has beta support for the ADK firmware.
You can check out the library described in Slick USB 2 Serial Library.
It enables common USB-to-serial adapters to work with Android devices that have USB host mode without needing to root.
http://slickdevlabs.com/
I am currently using the library in my own app, however I think you can get away with just the app that slick has on the market. There are two free apps and one is the "pro" version of one of the free ones; search slick usb in Google Play.
It does use HOST mode and you can change the baud rate to whatever you need.

Categories

Resources