ssw ssw - 1 year ago 149
Android Question

Does Android Wear support HttpURLConnection - getting EOFException

I am wondering if we can access the network through HttpURLConnection from Android Wear?

I tried using HttpURLConnection inside Wear code, I am getting EOFException. The same code works from regular Android phone. It only has problem when it is on Android Wear.

If HttpURLConnection is not supported on Wear, should we use Apache Http client or something else?

Or perhaps the way I am launching the app for development is incorrect?

URL url = new URL(myurl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(10000 /* milliseconds */);
conn.setConnectTimeout(15000 /* milliseconds */);
// Starts the query
int response = conn.getResponseCode();

I did add the permission into android manifest. I also run the above code from an AsyncTask.

EOFException occurs at conn.getResponseCode().

Thank you very much for your help.

Answer Source

Unfortunately, no.

Android Wear applications cannot directly access the Internet. They must communicate with their corresponding handheld app (either via MessageApi or DataApi) and request that it executes whatever HTTP requests you need.

EDIT: Android Wear 2.0, now in beta, supports network requests, so HttpURLConnection should work there.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download