3

Android Wearable.API is deprecated ? so what do we need to use to build the api client.

My current code is

mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addApi(Wearable.API)
                .build();
        mGoogleApiClient.connect();

//From this the Wearable.API is deprecated.

I have gone through this link https://developers.google.com/android/reference/com/google/android/gms/wearable/Wearable#getDataClient(android.app.Activity,%20com.google.android.gms.wearable.Wearable.WearableOptions)

Here they have asked to change it to data client and message client.

So can anyone help me with some kind of example exactly how to do it ? Thanks and Regards,

Update : Is the following correct way ?

 .addApi(Wearable.getDataClient(MainActivity.this).getApi())
.addApi(Wearable.getMessageClient(MainActivity.this).getApi())

If so then what is the use of interfaces of onMessageReceive() and onDataChange(). I mean I am already implementing them.

Pritish
  • 1,284
  • 1
  • 19
  • 42

1 Answers1

0

Please see the Google documentation here on migrating from the GoogleApiClient to objects based on the GoogleApi class.

https://developer.android.com/training/wearables/data-layer/migrate-to-googleapi

WildStyle
  • 99
  • 4
  • So which object do I need to use to connect with my wear ? – Pritish Jun 06 '18 at 08:42
  • 2
    Even in the example provided by them on github, they are still using GoogleApiClient to connect in service written for wear, and it has not been updated since two years. – Pritish Jun 06 '18 at 08:46
  • Right - my understanding is as per the docs, as the example here shows: https://github.com/googlesamples/android-DataLayer/blob/master/Wearable/src/main/java/com/example/android/wearable/datalayer/MainActivity.java – WildStyle Jun 06 '18 at 09:05
  • Do see what you mean about the service layer example though, that is still using the GoogleApiClient. – WildStyle Jun 06 '18 at 09:11
  • https://github.com/googlesamples/android-DataLayer/blob/master/Wearable/src/main/java/com/example/android/wearable/datalayer/DataLayerListenerService.java – Pritish Jun 06 '18 at 09:14
  • Please see line number 53, now I need to manually connect my phone to wear app and start an activity, they have done it from wear to phone, I need to do it other way, connect from handheld to wear,and it is deprecated. – Pritish Jun 06 '18 at 09:15
  • https://developer.android.com/training/wearables/data-layer/migrate-to-googleapi this doc link is broken also the github sample project – Sarath Siva Sep 25 '21 at 03:42