Direct Internet connection on Android Wear?

I tried to create an application showing some photos from the Internet.

I used a function that works fine on my phone (Galaxy S3 - Android 4.3), but on the watch I get a java.io.EOFException exception.

Code (works by 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 watch is paired online as well, since I can use voice commands and search the Internet, etc.

So the question is: can I access the website directly from Android Wear or do all these tasks on my phone? Or is there something wrong with my setup?

+6
source share
4 answers

Android Wear devices do not have direct access to the Internet. If you want to access the Internet, you must do this using your companion app. You can use the Data Layer API to transfer data back and forth between a wearable and a portable device. The data-level API has built-in support for asset transfers (mostly images, but basically you transfer any other binary data).

EDIT: With Android Wear 2.0, you can directly access the Internet using the regular network APIs. See Android Wear 2.0 Developer Preview for more details. Android Wear 2.0 has not yet been released; see Developer Timeline Overview on the Timeline.

+8
source

Even if Android 5.1.1 supports the Wi-Fi function.

You must adhere to the data-level API, you cannot send an HTTP request directly from chat. Extract Internet data from your phone, and then transfer it for viewing using the Data Layer API.

You can see this . Does Android Wear support internet access?

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

+2
source

I have a very similar problem. My application connects to the Internet using middleware (ZeroC Ice), so I can't use MessageApi or anything like that. My download application was able to connect to the Internet until it was connected to my phone.

My problem was that Wi-Fi is disconnected when the phone is connected to my Wear device (to save battery). A simple solution is to disable this feature: go to Developer Options at your own expense and disable Automatic Wi-Fi toggle . This will drain the battery faster, but each time you will be connected to the Internet.

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

+1
source

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

0
source

Source: https://habr.com/ru/post/971906/


All Articles