Draagon Draagon - 16 days ago 5
Android Question

Direct internet connection on Android Wear?

I tried to build an app showing some pictures from the internet.

I used a function, which works great on my Phone (Galaxy S3 - Android 4.3) but on the watch i get a

java.io.EOFException
exception.

The code (works on phone):

private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;

public DownloadImageTask(ImageView bmImage) {
this.bmImage = bmImage;
}

protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
//Log.e("Error", e.getMessage());
e.printStackTrace();
}
return mIcon11;
}

protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}


Other functions throw a
org.apache.http.NoHttpResponseException

The watch is paired and online as i can use voice commands and search the web etc.

So the question: Can i access the web directly from Android Wear or do need to handle all these tasks on my phone? Or is there something wrong with my setup?

Answer

Android Wear Devices have no direct access to the internet. If you want to access the web, you should do so using your companion app. You can use the Data Layer API to transfer data back and forth between the wearable and the handheld. The Data Layer API has built-in support for transferring assets (mostly images, but basically you transfer anything other binary data).

EDIT: As of Android Wear 2.0, it is possible to directly access the internet using regular network APIs. See the Android Wear 2.0 Developer Preview documentation for details. Android Wear 2.0 has not yet been released yet, refer to the Developer Preview Program Overview for a timeline.