2

I'm developing my first android wear application and I'm doing a request to an api, the problem is that I don't have internet connection. How can I enable the internet connection or something like that?

so far what I have tried is enable the bluetooth connection but every time I click there I get the following error Unfortunately, settings has stopped.

enter image description here

any idea how to fix it?

Note: below is my virtual machine details:

enter image description here enter image description here

EDITED Also to make sure the internet connection is not working I have tried the code below:

ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo ni = cm.getActiveNetworkInfo();
        if (ni == null) {
            // There are no active networks.
            return false;
        } else
            return true;
gon250
  • 3,405
  • 6
  • 44
  • 75

3 Answers3

6

Yes as it is documented that a wear does not have the direct access to internet so you cant call the API directlly from android wear.

There is a work around which i have used in one app i recently developed in wear.

You have to user the Message API for the android device and wear. Using this you can communicate with device and wear.

You can pass the action in Message API from device to wear. So what you can do is based on a specific action you can pass control to device call the API got the data and pass the required data to wear and do the operation you need.

And yes it is important that Google Play service is same or updated on both android device and wear (Device or Emulator) otherwise it will throw exception.

Thanks.

Hardik Chauhan
  • 2,750
  • 15
  • 30
3

UPDATE: The new Android Wear 2.0 allows the direct internet connection

Wael hamadeh
  • 755
  • 1
  • 6
  • 14
0

Running it from the terminal and manually setting a dns-server did the trick for me:

emulator -list-avds
emulator -avd Wear_OS_Small_Round_API_30 -netdelay none -netspeed full -dns-server 8.8.8.8

In this command snippet, I used the first command to see the name of the Wear OS emulator, and the second command to run the emulator with full speed internet using Google's DNS server.

As a sidenote, here's my .zshrc variables to run these commands:

export ANDROID_SDK_ROOT=/Users/${USER}/Library/Android/sdk
export PATH=$PATH:${ANDROID_SDK_ROOT}/emulator
konnovdev
  • 823
  • 8
  • 16
  • so far this has been working fine for me, but sometimes i'd need to turn on the airplane mode and turn it back off – konnovdev Nov 30 '22 at 13:58