Book Image

Android Wearable Programming

By : Steven F. Daniel
Book Image

Android Wearable Programming

By: Steven F. Daniel

Overview of this book

Table of Contents (14 chapters)
Android Wearable Programming
Credits
About the Authors
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Establishing connections for the mobile activity


Until now, we have created our project and the user interface for the mobile in our application. Also, we have set up our permissions so that our application can communicate with the Internet and Google Play Services.

In order for our app to communicate between the handheld and the Android wearable, we will need to establish a connection:

  1. From the Project Navigator window, expand the mobile section, select, and expand the java section.

  2. Next, double-click to open MobileActivity.java, and add the following code snippet:

    public class MobileActivity extends ActionBarActivity {
    
      private GoogleApiClient mGoogleApiClient;
      private static final String LOG_TAG = "MobileActivity";
    
      // establishes a connection between the mobile and wearable
      private void initGoogleApiClient() {
        if (mGoogleApiClient != null && 
        mGoogleApiClient.isConnected()) {
          Log.d(LOG_TAG, "Connected");
        }
        else
        {
          // Creates a new GoogleApiClient...