5
votes

I have an Android app running on a phone that's connected to a host machine over USB. The phone will always be connected to the machine and I need to go an HTTP request to the machine. Working in the emulator, I can access the webserver running on the computer using the IP address of 10.0.2.2 and that works fine. However running the same app on the phone, I get a SocketException of Network unreachable. The phone doesn't have a SIM card in it, nor does it have a wifi connection, I need the HTTP request to just go over USB to the computer. Is this at all possible? If so, what am I doing wrong.

I'm using standard HttpClient code, nothing special, which works absolutely fine if I run it on the phone using a wifi connection, so I know that's not the problem.

3
I don't think that is possible. Even if it were usb usually doesn't use ip addresses to identify devices. - mibollma

3 Answers

2
votes

I ended up abandoning this and basically polling the phone for the new content I wanted from the computer using adb.

1
votes

Reverse Tethering! not sure if it works. I never tried it. This thread might help:

https://android.stackexchange.com/questions/2298/how-to-set-up-reverse-tethering-over-usb

0
votes