Regarding Android Accessory mode and normal usb connectivity - android

I just started looking into OAPavailable in android.I came accros few doubts
Is accessory mandatory my android phone/table for me to talk to an external device over usb?Cant I talk to my external hardware using normal usb mode?Accessory mode means the phone will always be USB device and my external device will be the USB host.My application in phone should be able to talk to the external hardware regardless whether its a host or a USB device
What exactly are the difference between a USB host and device? Is it just that who powers the bus?When two devices connect how the device say "hey i will be the host and u be the device?"
In short my aim is I want to create an application that can talk to a usb device connected regardless its a usb device or a usb host.Can I acheive it using UsbManager apis without depending on OAP of Android

If you want to be able to work in either situation, you will basically have to write two communication subsystems, one using the APIs appropriate for each case.
It will be the external device and cabling which determines which mode is active (though if the phone cannot be a host, the connection of something external which requires that will be ignored, meaning no communication).

Related

How to Monitor CPU/Memory/GPU Usage of an Android Device without Connecting it to a PC?

Based on my understanding of Android Monitor, an Android device needs to be connected to the machine that is running Android Studio in order to profile CPU/memory/GPU usage. Are there any methods that allow profiling an app without connecting it to the PC? For example, writing the debug info that is generated for Android Monitor in a file and process the file later?
My goal is to gather debugging information without connecting the Android device to a PC (either via a USB cable or over the network).
Your initial work with a device usually needs to be over USB. However, after that point, you can switch using adb over the network, using adb connect. Once you have adb connected over the network, everything works just as if you had connected it via USB, including full Android Studio access.
Bear in mind that:
Some devices do not need the initial USB connection, as they are designed to work with adb over the network "out of the box" (e.g., Fire TV)
I think that older devices may not support this, for some value of "older"
You cannot monitor it without an active debugging connection. That being said, debugging connection isn't limited to USB. You need some kind of connection, and that connection can be USB, but it can also be over the internet(refer How can I connect to Android with ADB over TCP?).
Some devices don't support this, some have a setting for it in developer settings, and using root you don't need a connection. For devices that support adb over the internet, but aren't rooted or have the setting in developer settings, you need to have a usb connection initially.

Android USB Roles when Charging + Transmitting Data

I am aiming to be able to send a small chunk of data from a USB accessory to an Android phone, after the accessory is enumerated (in other words, on connection). The USB accessory is a charger which we will be designing.
As I understand:
The USB host is the one enumerating the devices, so that would have to be the Android device. But could the USB master be the one consuming the power?
If not, then if the Android device is acting as an accessory, could it be the one polling data?
If so, am I actually using USB OTG or not?
Would the accessory need to comply with Android Open Accessory specification to do such a thing?
Since it is sending the data on connection, I wouldn't be going into charging + sending data issue, right?
References I've been reading:
https://developer.android.com/guide/topics/connectivity/usb/index.html
https://developer.android.com/guide/topics/connectivity/usb/accessory.html
https://developer.android.com/guide/topics/connectivity/usb/host.html

Android to Android Communication over USB

Basically I need to build an APP to communicate between two android devices, send and receive data, in the safest way without Internet.
I could use WiFi, but they are prone to hacks and Jamming. My first question is
if Local WiFi Hot Spot connection could be made fully secured to public?
I am looking into wired communication between android devices using OTG USB serial communication. My second question is
Are there ways to communicate between android devices over OTG-USB using serial ports?
As Android supports both USB gadget and USB host interface, it is definitely possible to make communication between two devices over USB OTG. In this case, your one device will become USB Host which will initiate connection. And the other will become USB gadget device. And you will have to write application considering that.

Connect two android devices via USB

I'm trying to figure out how to connect two Android powered devices,
namely a smartphone (Android 4.1.2) and an android developer
board (Android 4.0.4) with apps running on each, via USB and get them
to communicate with each other.
Right now the developer board is running as the host and the phone as
an accessory. The hosts app is searching for connected devices and is
able to identify the phone as a device, but the app running on the
phone isn't able to find the host.
I've searched the web for quite a while now (!!) but I didn't come
up with anything helpful yet that solved my problem.
For my project it is crucial that I use an USB connection, so please
don't propose that I use bluetooth, WiFi, or anything else...
Regards
USB is host initiated, so it's not surprising that this is not working. Your device that is functioning as the USB device should respond to requests initiated from the USB host. You will probably have to create some sort of vendor specific protocol around this. I don't know what you are trying to do with this connection, but if the device needs to know things on the host you will need to bake this in to your protocol definition and send that information directly to the device.
What you could try doing is using both devices as a host and connecting a USB to UART bridge device between them, then you can transmit data generically in any direction by using the serial connection (through USBManager if the USB protocol is available, or some Android Java Serial class if it is not), plus you don't have to worry about the host-device connection. This would look something like this:
[Android 4.1.2 Device]<--USB Connection-->[USB to UART Bridge]<--Serial Connection-->[USB to UART Bridge]<--USB Connection-->[Android 4.0.4 Device].
Use OTG Cable to interact with your board and phone. Its easily available in the market.

Android WiFi Peer-to-peer (P2P): how to mock the second device using a computer?

Suppose you only have one android device, but you would like to experiment with the Wi-Fi P2P API. Is it possible to use a computer to mock the other wifi device running whatever OS and application that is necessary to play the other part in the P2P communication?
I know the android emulator doesn't support wifi.

Categories

Resources