Http://developer.android.com/training/wearables/data-layer/accessing.html
accessing the wearable data layer-layer connection
Googleapiclient is a portal for consolidating all of Google services, and to connect to the data layer, you need to build an object.
Googleapiclient provides a builder method to simplify the steps of building objects.
Googleapiclient mgoogleapiclient =NewGoogleapiclient.builder ( This). Addconnectioncallbacks (Newconnectioncallbacks () {@Override Public voidonconnected (Bundle connectionhint) {log.d (TAG,"onconnected:"+connectionhint); //Now you can use the Data Layer API} @Override Public voidOnconnectionsuspended (intcause) {LOG.D (TAG,"onconnectionsuspended:"+cause); }}). Addonconnectionfailedlistener (NewOnconnectionfailedlistener () {@Override Public voidonconnectionfailed (connectionresult result) {LOG.D (TAG,"onconnectionfailed:"+result); if(Result.geterrorcode () = =connectionresult.api_unavailable) { //The Android Wear app is not installed } } }) //Request Access only to the wearable API. Addapi (WEARABLE.API). build ();
important : When a device does not have "Android Wear" installed, then Googleapiclient will return a connection failure, callback onconnectionfailed this method, The error code is connectionresult.api_unavailable. If you want to keep other Google services working properly, you should separate the Googleapiclient objects that connect the wear API from the objects of other services.
After calling the Connect () method of googleapiclient, we try to connect the service, and then callback Onconnected () After the connection succeeds, in which we can invoke the data-tier API.
Android Wear development-Data Communication-section I: Connecting the data layer