Forum Xamarin.Android


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

How do I (WiFi) debug USB device connections?

Hi all! I'm developing a Xamarin.Android app for work (on a PL-40L PDA running Android 7.0 (https, and we need to connect to an Arduino Due. We've settled on having the Due act as USB Host (Arduino-er) (http, because we want to charge the PDA, and when I ran the Arduino sketch and the Android app, I got communication to occur. However, while attempting to debug my attempt using WiFi (https, every time I connect or disconnect the Arduino via USB, debugging in Visual Studio disconnects. I've searched, and the closest I've gotten to a similar issue is unresolved (Stack Overflow) (https In any case, all this is incidental to hooking into the USB accessory attached broadcast (Android.Hardware.Usb.UsbManager.ActionUsbAccessoryAttached). So:

  • Can anyone help with keeping WiFi debugging going when connecting a USB device?
  • Alternatively, does anyone know how to reconnect debugging to an Android device when it disconnects like this?
  • Any tips for getting USB attached hooks working? (I'm happy to ask another question for this one)

Your help is GREATLY appreciated.



  • JonathanJohansenJonathanJohansen Member ✭✭
    edited October 2018

    Thanks @BillyLiu, it didn't help, unfortunately. I've resigned myself to it - with a debug text file (I should probably figure out how to use some web thingy to make 'debug' print statements really easy...)

  • LearnEverythingLearnEverything USMember ✭✭✭
    1. Create a text file and copy code below, then rename it as .bat file.
    2. Copy the ip address from your android device wifi in settings, then paste replace in cmd text e.g "adb connect" (ip address is "")
    3. Open .bat file cmd on Windows
    4. Now you can disconnect your android device connected usb cable and check if the device name has appeared in the Visual Studio device listing
    @echo off
    if _%1_==_payload_  goto :payload
        echo %~nx0: elevating self
        set vbs=%temp%\getadmin.vbs
        echo Set UAC = CreateObject^("Shell.Application"^)                >> "%vbs%"
        echo UAC.ShellExecute "%~s0", "payload %~sdp0 %*", "", "runas", 1 >> "%vbs%"
        del "%temp%\getadmin.vbs"
    goto :eof
    cd C:\Program Files (x86)\Android\android-sdk\platform-tools
    adb tcpip 5555
    adb connect
    echo...Script Complete....
Sign In or Register to comment.