Android Host Mode USB debugging - android

I am developing an application where my android phone connects to a USB accessory. However, when the accessory is connected is there any easy way to debug the application?
Can we use a micro usb hub or similar device?

When debugging applications that use USB accessory or host features, you most likely will have USB hardware connected to your Android-powered device. This will prevent you from having an adb connection to the Android-powered device via USB. You can still access adb over a network connection. To enable adb over a network connection:
Connect the Android-powered device via USB to your computer.
From your SDK platform-tools/ directory, enter adb tcpip 5555 at the command prompt.
Enter adb connect <device-ip-address>:5555 You should now be connected to the Android- powered device and can issue the usual adb commands like adb logcat.
To set your device to listen on USB, enter adb usb.
source: Android developer site

You could write an app that reads the logcat output on the phone and displays it on the screen and/or saves it to a file which you can pull with adb afterwards.
The app must be given READ_LOGS permission, which you can do with adb shell pm grant com.package.appname android.permission.READ_LOGS (at least on a rooted phone).
Another alternative might be to log over WiFi. adb has an option to connect over TCP/IP, but this is not something I've tried so I don't know how difficult it is to set up or how well it works.
Unless your logs are really verbose it's sometimes enough to run through your USB accessory use-case and then unplug the accessory and connect the phone to your computer to catch the logcat output. The logs are buffered up to a certain amount, so you can get a reasonable amount of logs using this method.

You could run an Android image in Virtualbox. This would allow you to connect your USB device to the virtual device, and debug over the bridged network connection.
I haven't figured out how to convert the SDK .img OS images to VDIs for use in Virtualbox, but there are plenty of canned VDIs out there.

Related

ADB tcpip only listening on ipv6 interface

I have an android head unit that I am developing an application for. I need to be able to debug over wifi. However when I setup adb tcpip 5555 etc.. I cannot connect. I checked the netstat output from the device and sure enough its listening on :::5555
Does anyone know if there is a way to get adb to listen on ipv4 addresses? The device is not rooted by the way. The link to the device is : https://www.amazon.com/dp/B08HPZP1NV/?th=1
The model is: ATOTO S8 Standard
Getting this device to even show up on USB took installing a "settings app" that the developers removed, turn on usb debugging, then switch usb mode to host mode (I think it says host mode as its in Chinese).

Unpluging usb cable also disconnects wireless adb connection [duplicate]

I develop on my tablet using android studio.
The tablet is connected to the computer by wifi using
adb connect <ip_andress>:5555
My application contains listeners for USB devices attached/detached.
But unfourtunately, when I connect/disconnect usb device to/from the tablet, the adb connection is getting killed, and I can no longer see the device under "adb devices".
It is not a adb-connection-by-wifi what gets killed. It is just that USB enumerations affect the sys.usb.* system properties which on many devices is causing restart of adbd regardless whether it's being used over USB or tcpip.
Do grep "stop adbd" /init*rc to see what I mean.
You could either comment out those stop adbd lines or just disconnect the USB cable before running your adb connect command.
I was never able to connect my cellphone with my computar through wi-fi.
I had already given up. I followed all the instructions and tips, and nothing worked.
Finally, I did what no one said to do.
I've connected the phone to the WiFi network provided by the cable modem itself and not to some (not all) additional networks that are included in the router.
At home I use one of these networks, because I use a Deco Tp-Link router, which propagates the signal to my entire house, but this network is NOT compatible with ADB. It does not identify it as belonging to the same network.
After this, I use the normal procedure described here.
a) Connect cellphone with a USB cable
b) Find the IP_Phone depends on system in the cell phone. Here I use Settings, About Phone, Status and IP address.
c) Run the following adb commands in Command Prompt (Windows) or Terminal (Linux), where IP_Phone is the IP above mentioned. Normally adb.exe is an executable stored in computer path. adb is already included in Android Studio package.
adb tcpip 5555
adb connect IP_Phone
d) Now disconnect USB cable and it's ready. The cellphone model continues to appear in the status line in the top of Android Studio.
-/-
The best wifi is that defined in Cable Modem. It, unlike an any account defined in my router, answers to a ping command.
ping IP_Phone
Disconnect the usb cable just before running adb connect <*ip_address_of_your_phone*>

How to get adb logs via bluetooth?

How to get adb logs via bluetooth?
need to connect an android device to my laptop to get the adb logs, but through usb cable its not working.
Dude, you don't need Bluetooth to do so, you can get ADB logs via Wi-Fi.
The steps:
Connect your device to your laptop via USB (yes, you've read right, if your USB cable is not working, you can use an alternative USB cable temporarily or borrow one from your friends).
Type adb tcpip 5555 in the terminal
Type adb connect XXX.XXX.X.X (the X's represent the local IP address of your mobile device, if you don't know your device's IP, go to Settings > Wi-Fi > Advanced).
You can disconnect your device from your laptop and now you can debug your apps wirelessly.
If you really need Bluetooth to use ADB. Bad news! That's not even possible.

adb wifi often go offline, how to keep adb online?

I'm using Android tablet communicating with a USB device through USB port, the tablet only has one usb port, so I use adb wifi as my debug tool. However, when I connect adb through WIFI, the connection won't keep long(only a few minutes us usually), how to keep the adb wifi connection online all the time?
Another question, is it possible to use USB HUB to connect the tablet with both USB flash-drive and my computer, and keep adb running?
Many thanks!!!
After lots of unsuccessful attempts,I have noticed that turning Allow ADB debugging in charge only mode specification on , solved the problem . It makes the device online and accessable over wifi to ADB.
You can find it under Developer options section.
Here is what I found out from researching everywhere and developing on my own for more than a week.
Q1. adb service often crashes if it is not doing any executions for a long long time.
A1. calling adb commands time to time keeps adb server online.
Q2. wifi connected device sometimes disconnect.
A2. Before you check your wifi on the connected device, check the wifi that your ADB server is running on. Ping to google and if it is well connected, ping to the device.
Wireless can disconnect on its own and even wired connection is sometimes disconnected. so calling "adb connect ..." when the device is not already connected is necessary. You could do this easily by saving "adb devices > device.txt" and query out whether your expected wifi is on the list. If not, connect again..(do this in another thread).
Q3. wifi connected device is sometimes offline.
A3. This is because by TCP/IP connection your ADB server is now on Time_Wait stance. The last connection was interrupted that the next connection is now offline because the last connection is not completely shut down. You can either manually disconnect/connect your device's wifi or restart TCPIP connection by ex) "adb tcpip 5555"
If you want to do this automatically, you are going to have to disconnect/connect your device's wifi programmatically.
Leave any other questions and I can answer on the comments.
When connection is lost and adb devices shows device is offline, like this:
prompt> adb devices
List of devices attached
192.168.1.1:5555 offline
then adb disconnect IP followed by adb connect IP will often work:
prompt> adb disconnect 192.168.1.1
disconnected 192.168.1.1
prompt> adb devices
List of devices attached
prompt> adb connect 192.168.1.1
connected to 192.168.1.1
prompt> adb devices
List of devices attached
192.168.1.1:5555 device
Use adb over wi-fi without any third-party apps. Follow the steps.
Connect device via USB
Open your terminal and check your device is listed with adb devices command
Type adb tcpip 5555 and enter (or use another port instead of 5555)
Plug out your USB cable. You don't need it anymore.
Take your Android phone and go Settings/About/Status
Check the IP address part. Let's say your IP address is 192.168.x.y
In your terminal, write the command adb connect 192.168.x.y
Now, you have connected your device via wi-fi.
You can see your device in adb devices
Enjoy it! :)
This seems like an issue with your wifi. As a precaution, just keep the terminal open and whenever you need to test just press the 'UP arrow' key to get to previously ran adb connect "<ip>" command.
I tried many ways but this one worked out for me:
force the display on and of in a loop would keep the device online
adb shell input keyevent 224
timeout 2
adb shell input keyevent 26
timeout 58
this turns the display on every minute for 2 seconds
So, I'm using Scrcpy and Adb to wirelessly connect to my Phone(for developing Flutter Apps) and since the screen wasn't staying awake even by Scrcpy --stay-awake command.
I had to change Lock Settings=>Lock Screen => Sleep, and settings to Never Sleep.

ADB over ethernet

I have an android device which I want to connect to using ADB. For reasons that don't matter here I need it to have an ethernet connection, not wifi. The device itself refuses to have both ethernet and wifi connections at the same time.
I have been using a third party app called ADB WiFi to connect to it with ADB when it is in WiFi mode, and I have found that I can connect to it in wifi, then switch the device into ethernet, and then reconnect to the new IP, and it works.
I would dearly like to be able to connect to my device (which is often remote and hard to reach) without first switching it into wifi and back, to which end I have written my own little app which uses SU and does:
setprop service.adb.tcp.port 5555
stop adbd
start adbd
It says that it is working when I run it and produces no error messages, but I can't connect afterwards. It doesn't work in wifi mode either. After setting up a connection once using the 3rd party app, I can then use stop adbd to prevent adb working, and I can use my application above to enable it again, without wifi or 3rd party intervention, which suggests that it is doing what it thinks it is doing, but missing a one off step.
Does anyone know if there is another thing that must be set / enabled / poked in order for adbd to work? Does anyone know what I'm missing?
Thanks
Have you tried this:
adb tcpip 5555
adb connect 192.168.1.1:5555
replacing the 192.168.1.1 with your phones IP Address?
I was able to get both ADB (through USB) and Ethernet, but it was device specific. I used the Asus Transformer Pad TF701T with the keyboard dock. The dock allowed me to connect the ADB cable and provided a full size USB port. I connected a compatible USB to Ethernet adapter to get Ethernet.

Categories

Resources