7

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?

Draagon
  • 118
  • 1
  • 5

4 Answers4

9

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.

Peter Friese
  • 6,709
  • 31
  • 43
  • 2
    Sad to hear they did not build this functionality into the Android Wear app on the phone and seamlessly deliver internet connectivity to the wear device (like on Google Glass). Now everyone has to write their own code for internet connectivity and put it in the phone app. – Fraggle Jul 08 '14 at 18:26
  • 3
    Does the companion app need to be launched by the user for this to happen? in other words, if the user has ever only run the wearable app, can it access that internet via the handset? – Ariel Vardi Jul 19 '14 at 21:44
  • Is this limitation still relevant now that new versions of Android Wear enabled wi-fi support on some watches (eg, Galaxy Gear)? I'm wondering if I can create an app for wear that can connect to the internet while the phone is not around – German Jun 12 '15 at 00:12
2

Even if Android 5.1.1 support Wi-Fi Feature.

You should stick to the Data Layer API , you cannot send http request directly from watch. Fetch internet data from the phone, then transfer it to watch with Data Layer API.

You can see this Does Android Wear support directly access the Internet?

And this document Always-on and Wi-Fi with the latest Android Wear update

Community
  • 1
  • 1
Hsiao yen
  • 71
  • 1
  • 5
1

I have a very similar problem. My app connects to the internet using a middleware (ZeroC Ice), so I can not use the MessageApi or anything like that. My wear app was able to connect to the Internet while not connected to my phone.

My problem was that the WiFi is switched off when the phone is connected to my Wear device (in order to save battery). A simple solution is to disable this feature: go to Developer Options on your wear and disable Automatic Wi-Fi toggle. This will drain your battery faster, but you will have Internet connection everytime.

Credits: https://arcoresearchgroup.wordpress.com/2016/04/18/wear-keep-internet-even-when-connected/#more-1349

oscarah
  • 113
  • 1
  • 6
0

You can use MessageApi. I followed this detailed example and it worked really well.

Chris Gunawardena
  • 6,246
  • 1
  • 29
  • 45
Harshul Pandav
  • 1,016
  • 11
  • 23