Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make HTTP Requests over WiFi directly from Android Wear?

how can I execute HTTP requests or open a socket on Android Wear? I used to think that's impossible but the Web Browser for Android Wear app says the folloing:

"[..] works even when your phone is off if you have a smartwatch with Android Wear 5.1 and WiFi"*.

I tested it and that app CAN connect the internet when the paired phone is powered off.

Whenever I open a socket or try HTTP requests on Android Wear I always get a ConnectException saying failed to connect to http://foo.com (similar stack trace here). So I'm doing something different then that app is doing and I'd like to understand what that is.

Context: I'm working on proof-of-concept and just want to be able to execute HTTP requests and open sockets. I'd love to know if there's any way to do that. Even if it includes rooting the watch and doing some adb magic.

To clarify: I know about the Data Layer API and i'd still like to be able to just do HTTP requests and open sockets.

like image 448
JustinAngel Avatar asked Jul 11 '15 00:07

JustinAngel


1 Answers

If your watch has Wifi and it is set up correctly, then you can make network calls on your watch when your watch is disconnected from the phone; when you connect to your phone via BT, wifi will be disabled. While it is enabled, you should be able to treat that as a usual network connectivity and make network calls. But keep in mind that if you write an app that relies on this, your app will fail to work when it gets connected to a phone so you need to handle that case and provide an alternative for your app to get the same data (i.e. using the phone's connectivity).

like image 122
Ali Naddaf Avatar answered Oct 21 '22 21:10

Ali Naddaf