Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Hands-on with Android Wear

Hands-on with Android Wear

A beginners guide to getting up and running with Android Wear.

Breandan Considine

July 31, 2015
Tweet

More Decks by Breandan Considine

Other Decks in Programming

Transcript

  1. Wearable Data Layer (Play Services) • Communication channel between handheld

    and wearables • Google Play Services behind the scenes • Provides three API for communication • Data Layer API • Node Layer API • Message Layer API
  2. Wearable Data Layer API (Play Services) • All wearable communication

    starts with the GoogleApiClient apiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(Wearable.API) .build();
  3. Wearable Data Layer API @Override protected void onStart() { super.onStart();

    apiClient.connect(); } @Override protected void onStop() { apiClient.disconnect(); super.onStop(); }
  4. @Override public void onConnected(Bundle bundle) { Wearable.DataApi.addListener(apiClient, this); Wearable.MessageApi.addListener(apiClient, this);

    Wearable.NodeApi.addListener(apiClient, this); } @Override protected void onPause() { super.onPause(); Wearable.DataApi.removeListener(apiClient, this); … } Listeners and Callbacks
  5. // Sender Wearable.MessageApi.sendMessage(apiClient, transcriptionNodeId, PATH, byteArray); // Listener public void

    onMessageReceived(MessageEvent me) { if (me.getPath().equals(PATH)){ … } } Message API • One-way communication channel between local and remote node
  6. PendingResult<CapabilityApi.GetCapabilityResult> capability = Wearable.CapabilityApi.getCapability( mGoogleApiClient, VOICE_TRANSCRIPTION_CAPABILITY_NAME, CapabilityApi.FILTER_REACHABLE); @Override public void

    onCapabilityChanged(CapabilityInfo info) {…} <?xml version="1.0" encoding="utf-8"?> <resources> <string-array name="android_wear_capabilities"> <item>voice_transcription</item> </string-array> </resources> Capability API
  7. Voice Actions • Like handheld, launching a wear app defaults

    to android:label <activity android:name=".WearActivity" android:label="WearActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> … </activity>