Android Wear development-Data Communication-section I: Connecting the data layer

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.