Direct internet connection on Android Wear?

爱⌒轻易说出口 提交于 2019-11-26 21:21:57

问题


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?


回答1:


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.




回答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




回答3:


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




回答4:


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



来源:https://stackoverflow.com/questions/24627174/direct-internet-connection-on-android-wear

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!