I'm just starting on some development using the android accessory protocol. I have sourced a starters kit (microchip) to get familiar with the environment. I should note that I' have a solid background in embedded C, but not really in Android / Java.
The kit connects using USB, so I have configured my phone to use ADB over Wifi, which works great. I compile the app and can debug in the phone just fine. However, it will not recognize when the accessory is connected to the USB port. When I stop the wireless ADB, the app will recognize the accessory just fine and works as it should.
I have a hard time finding out whether this is expected behavior or not, but as it would stop any debugging on an app communicating with a USB accessory I doubt it and suspect I am doing something wrong.
I use a Galaxy S3 I9300 rooted, and microchip's Accessory Development Starters Kit and provided samples.
ADB-over-wifi does disconnect after an accessory is connected. To mediate that, switch the phone to accessory mode and after that connect the ADB-over-wifi. That way eclipse can reconnect to the debugging session.
Another way is to run a shell a shell script in the background that will infinitely connect the ADB-over-wifi.
I did not find more elegant ways to solve this problem.
Ok. it seems to be related to the "USB Debugging" option in the developer options. When I disable it, it works as expected.
I have not been able to try it on lots of different phones but on the 2 I have access to this seems to be consistent (Galaxy S3 and HTC One).
I can't find any specifics on this behavior on the net though.
Related
My MacBook computer battery is broken and somehow it has not enough power to power device by usb-c adapter so I cannot connect anything and only have to use android emulator. But I need to debug on real device while testing some ocr sdk that obviously don't want to recognize anything in android emulator virtual scene. I asked other question about that but still I am puzzled by this inability to use WIFI for usb debugging because sdk runs fine on my phone but to debug using fabric and APK deployment is really horrible dev experience and productivity.
Is there some way I can setup WIFI debugging without cable at all... Maybe I need to root my device but again how to do it without cable, it seems impossible either way. I feel in like in dead and but still asking question here. I have computer and phone but cannot connect them for debugging by wifi.
Afraid I don't have an easy wireless solution. The closest thing I could find is that android wearables may have a debug over bluetooth feature, but it's built to route through another (wired) android device.
There is likely a feasible wired solution though- you can hook the device to a powered hub and the hub to the computer.
You could also use an adapter of sorts. They were built for printers and such before everything came with wifi and could get a proper wireless setup going without either side realizing they aren't directly connected over USB (OS still knows that some funky usb drivers are loaded and a separate application may need to run to connect), but again more hardware. A decent Wireless "USB Device Server" seems to run ~$100 while wired ones are cheaper, but not as cheap as a powered usb hub.
If you have another machine, you can use it to enable wireless debugging on your Android phone. See https://developer.android.com/studio/command-line/adb#wireless. Once wireless debugging is enabled, you can connect to it from your Mac without using USB. You still need USB for enabling wireless debugging though, but you can do it from a different machine. This should work on all Android phones, root is not required.
Update [2021]:
Things have developed since this question was asked. WiFi Debugging is a first class option now on newer devices. See https://developer.android.com/studio/run/device.html#wireless for details.
I am creating an app (running in USB accessory mode) that will recognise when a specially made device (that I am also working on) is plugged in and connect to it.
I have written code in the app for this recognition to happen but now need to test it and the specially made device is not made yet.
So, I was wanting to test my app by somehow setting my PC up to be recognised as a usb host device that my phone can connect to, I spent a long time googling and looking for a way to do this or a different way to test this but came up empty.
How do I set my PC up in this way to test my app or what would be a good way to test this automatic usb connecting?
Thank you kindly,
EDIT:
Even the name of a cheap device that runs in android usb host mode would be sufficient as I could still just plug that into my device to check if it is working.
I think your question is how to emulate USB Host mode with the Emulator and setting up a bridge with an emulated device on the PC. This is not possible (yet).
See Emulator documentation. In the "What's not supported section" it is said that virtual hardware is not supported for USB.
I'm developing an Android Accessory using a Galaxy Nexus phone and the official Arduino ADK board. I'm using all the standard Arduino libraries available here. I'd like to be able to debug my Android code at runtime so I followed Googles' instructions in their "Debugging Considerations" documentation in order to do remote debugging via WiFi.
When I connect to the phone via USB I'm able to debug just fine (of course it's not talking to the Arduino board though). When I connect to the phone via WiFi I can debug just fine. However when I plug in the board to the phone it no longer auto-launches my application (that's registered with the ADK device). So instead I manually start my application but it cannot find the Arduino accessory. If I switch back to USB debugging and reconnect the ADK board to the phone it auto-launches like normal and everything is fine, but then I'm back to not being able to debug.
There are no changes to the code during all of this. All I did was change how the adb tool reaches the phone. Any guesses why the phone and my application can no longer see the ADK board?
In short:
If the phone is set to debug via USB, it can talk to the Arduino ADK with no problems.
If I invoke "adb tcpip 5555 < enter> adb connect < device-ip-address>:5555" I can remotely debug the phone with no problems.
If I now connect the ADK board to the phone with the USB cable, the phone cannot find the ADK board, but I can still do remote debugging via WiFi. That's how I know that the accessory cannot be found.
Edit:
The phone is running Android 4.1.1 and the Arduino is 1.0.1.
Just bumped into this problem, having returned to USB Accessory work. Yes there is a problem, I've no idea how to fix the problem as later versions of Android simply don't allow you to both run adb over wifi and USB Accessory at the same time. My solution and you probably got there already yourself was to root my phone, luckily a Nexus S, and down grade the Android on it to 2.3.6
It's not a great solution but to debug USB Accessory I have to boot into 2.3.6. Hopefully in the future this might work again.
Debugging USB Accessory through wifi is only possible on Nexus devices. I tried many others (Samsung's, Motorola), they don't detect accessory when USB debugging is enabled in settings. Also tried hardware usb switcher - does not help.
I have a general and quick question and since you can never get a hold of a developer at Google, I thought I would post the question here...
Can anyone tell me, if we want to use our phones to connect via USB to a missile launcher made by dream cheeky As suggested on the USB or ADK section of the developer's website, would we still need and Arduino board or a board that Google presented at Google I/O 2011?
I guess I am asking, in short, can we directly hook our phones to another device via USB, and compile a program via eclipse or with the ADK to have it run? or will we still need a board in between the phone and the device we want to connect USB...
Thanks in advance,
Richard
In ADK, the Android device acts as a USB Device and the Android accessory acts as a USB Host. When an Android accessory is attached to the Android device, the Android devices switches to "accessory mode (as described in ADK)". If your Android device has USB host already, still it will switch to accessory mode and acts as USB Device instead of USB Host. Actually, the motivation behind ADK is to make each Android device to work with any Android accessory. Accessory mode eliminates the need for USB host, since only few devices has USB host feature (It is costly).
So, if you want to work with ADK, you need an development card with USB host.
you do not need an ADK board if the device that you are connecting to your Android device is acting as the USB Device and your Android device is acting as the USB Host. This is the case with the Dream Cheeky USB missile launcher. You can connect a missile launcher directly to the device and control it. USB Host is only supported on Android 3.1 devices and later.
I've been able to find a few posts on StackOverflow about how to control USB devices using an Android phone -- which I understand is impossible (The Android being a USB device and all.)
However, I would be perfectly happy to set up my application to communicate with the other computer (a Linux host) as a USB device. (Like a really expensive mouse...)
Does anybody have information about how to set up an Android app/phone to use the USB connection and exchange data with a host computer. Obviously, it already works at some level -- it's how Eclipse and Android SDK/debugger do what they do, but I'm still looking for some way to do this in an application.
(My current phone, BTW, is a Droid Incredible.)
Thanks,
R.
Basically you'd need to install the USB device driver and the ADB toolsuite from the SDK, either that or reverse engineer their functionality and build it into something else.
Then you enable USB debugging on the phone.
And then you can do something like an adb port forward to allow an application on the pc to connect to a network socket listener on the phone. Note that connections cannot be made in the other direction, but once a connection is made it is bidirectional.
If your version of android supports tethering over USB, you could also leverage that to implicitly create a network between the PC and the phone, at which point you can make connections in either direction. Just make sure nothing starts accidentally pumping lots of data through the phone's mobile network!
(Many android phones actually can experimentally function as USB hosts, but you have to compile new drivers into the kernel, install the new version, and make up a cable to provide USB power to the device as the phone cannot. Also you lose the ADB over USB channel which makes debugging a pain)