Android Wear Presentation

40
Introduction to Android Wear Talk by Chua Zi Yong https://plus.google.com/ +ZiYongChua

description

Android Wear Talk at GDG Singapore

Transcript of Android Wear Presentation

Page 1: Android Wear Presentation

Introduction to Android Wear

Talk by Chua Zi Yonghttps://plus.google.com/+ZiYongChua

Page 2: Android Wear Presentation

Join GDG Singapore as member

• Keep up to date with Google products and technologies

• Make new friends that are also passionate about technology

• Interact with Googlers

• Access to selected exclusive Google events

• Find jobs and developers related to Google products

• Contribute to developer community

Learn more at www.gdg-sg.org/member

Page 3: Android Wear Presentation

Learn more at www.gdg-sg.org/member

Because pictures speak a thousand words

Page 4: Android Wear Presentation

Learn more at www.gdg-sg.org/member

For more membership details,

Get started today with just your email.

Visit http://bit.ly/gdg-sg-members

Page 5: Android Wear Presentation

What is Android Wear?

Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua

Page 6: Android Wear Presentation

What is Android Wear?

Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua

Notifications

Apps on Wear

Android Fit

Page 7: Android Wear Presentation

What is Android Wear?

Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua

Page 8: Android Wear Presentation

What is Android Wear?

Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua

Requires Android 4.3 and above Android device

Latest Google Play Services and Android Wear app from Google Play installed

Internet and connectivity over bluetooth from paired device

Limited function when connection is lost

Page 9: Android Wear Presentation

Getting Started – Install SDK

Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua

Install the Android Wear SDK Tools from ADT

• Android ADT Revision v22.6 and above

• Android Wear ARM EABI v7a system image

• Update Android Support Library

Page 10: Android Wear Presentation

Getting Started – Install emulator

Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua

To install and test Android Wear emulator, you need to (visit http://javapapers.com/android/android-wear-getting-started-tutorial/ for full details)

1) Sign up for developer preview http://developer.android.com/wear/preview/signup.html

2) Create AVD

3) Connect Android device over adb (adb -d forward tcp:5601 tcp:5601)

4) Install Android Wear Preview from Google Play

Page 11: Android Wear Presentation

Design for Wear

Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua

Wear apps should be

• Launched automatically

• Glance-able

• Works like a personal butler

• Zero to low interactions

Page 12: Android Wear Presentation

Design for Wear

Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua

Two ways you can think of Wear Interactions

• Extension of existing Android app notifications to work better on Android Wear (existing notifications on phone already appears on Wear)

• Android Wear specific app

Page 13: Android Wear Presentation

Notifications for Wear

Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua

Extending your existing notifications to Wear

• You can add voice input/actions directly from Wear

• You can add additional content in pages• By swiping left/right on the wearable

• You can stack multiple notifications

Page 14: Android Wear Presentation

Notifications for Wear

Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua

Adding actions to Wear (It is very simple)

• The same code before works the same on Wear (Including notification actions, big view)

• Use NotificationCompat.WearableExtender() for Wearable-only options (Appears only on Wear, not on phone)

• You can use addRemoteInput(remoteInput) to prompt user for voice input

• P.S. Always use the NotificationManagerCompat instead of NotificationManager (to support 4.1 and above features)

Page 15: Android Wear Presentation

Notifications for Wear

Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua

Adding actions to Wear (Eliza sample code)NotificationCompat.Builder builder = new NotificationCompat.Builder(this) // All the usual

stuffs .setContentTitle(getString(R.string.eliza)) .setContentText(mLastResponse) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.bg_eliza)) .setSmallIcon(R.drawable.bg_eliza) .setPriority(NotificationCompat.PRIORITY_MIN);

Intent intent = new Intent(ACTION_RESPONSE); // Intent to do your stuff PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT);

Notification notification = builder .extend(new NotificationCompat.WearableExtender() // New notification extension for Wear .addAction(new NotificationCompat.Action.Builder( R.drawable.ic_full_reply, getString(R.string.reply), pendingIntent) // Get voice input .addRemoteInput(new RemoteInput.Builder(EXTRA_REPLY) .setLabel(getString(R.string.reply)) .build()) .build())) .build();

NotificationManagerCompat.from(this).notify(0, notification);

Page 16: Android Wear Presentation

Notifications for Wear

Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua

Extending your existing notifications to Wear

• You can add voice input/actions directly from Wear

• You can add additional content in pages• By swiping left/right on the wearable

• You can stack multiple notifications

Page 17: Android Wear Presentation

Notifications for Wear

Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua

Adding additional content in pages (many at one time)

• For example, showing results of nearby search

• First, create an array list of notifications

• Next, generate a notification for each page you want to display, and add them to your array list

• Last, use .addPages(List<Notifications>)to parse in your array list

Page 18: Android Wear Presentation

Notifications for Wear

Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua

Adding additional content in pages (one at a time)

• First, create the main (first) notification builder

• Next, create the new notification you want to insert

• Last, use .addPage(Notification) to add your notification

Page 19: Android Wear Presentation

Notifications for Wear

Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua

Adding additional content in pages NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) // Main .setSmallIcon(R.drawable.new_message) .setContentTitle("Page 1") .setContentText("Short message") .setContentIntent(viewPendingIntent);

Notification secondPageNotification = new NotificationCompat.Builder(this) // Second Notification .build();

Notification twoPageNotification = new WearableExtender() .addPage(secondPageNotification) // Add second notification to main .extend(notificationBuilder) .build();

notificationManager = NotificationManagerCompat.from(this);notificationManager.notify(notificationId, twoPageNotification);

Page 20: Android Wear Presentation

Notifications for Wear

Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua

Extending your existing notifications to Wear

• You can add voice input/actions directly from Wear

• You can add additional content in pages• By swiping left/right on the wearable

• You can stack multiple notifications

Page 21: Android Wear Presentation

Notifications for Wear

Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua

Stacking multiple notifications

• Use .setGroup(String key) to group your new notification to existing group

• Use notify() to send the notification to Wear

Page 22: Android Wear Presentation

Notifications for Wear

Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua

Stacking multiple notificationsfinal static String GROUP_KEY_EMAILS = "group_key_emails"; // Key for group ID

Notification notif = new NotificationCompat.Builder(mContext) .setContentTitle("New mail from " + sender1) .setContentText(subject1) .setSmallIcon(R.drawable.new_mail);

.setGroup(GROUP_KEY_EMAILS) // Set group ID into notification .build();

NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);notificationManager.notify(notificationId1, notif); // Send out the notification

Page 23: Android Wear Presentation

Design for Wear

Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua

Two ways you can think of Wear Interactions

• Extension of existing Android app notifications to work better on Android Wear (existing notifications on phone already appears on Wear)

• Android Wear specific app

Page 24: Android Wear Presentation

Wear App API Architecture

Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua

Phone APK Wear APK

Page 25: Android Wear Presentation

Wear App API Architecture

Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua

Node API- Inform when Wear is connected

Message API- Manage API calls between devices

Data API- Centralized data storemanaged by GPS

GPS Magic

Page 26: Android Wear Presentation

Wear App API Architecture

Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua

Page 27: Android Wear Presentation

Wear App API Architecture

Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua

Page 28: Android Wear Presentation

Wear App API Architecture

Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua

Page 29: Android Wear Presentation

Wear App API Architecture

Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua

To start communicating with the Wearable, we need to initialize the GoogleApiClient on the phone APKmGoogleApiClient = new GoogleApiClient.Builder(this) .addApi(Wearable.API) .build();

mGoogleApiClient.connect();

Page 30: Android Wear Presentation

Wear App API Architecture

Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua

WearableListenerService will handle all the callbacks from Google Play Services on wear

// Insert the service into the manifest of the Weak.apk, in this case name it// AppListenerService (subclass of Abstract class WearableListenerService)<service

android:name=“.AppListenerService”><intent-filter>

<actionandroid:name=“com.google.android.gms.wearable.BIND_LISTENER”/></intent-filter>

</service>

Page 31: Android Wear Presentation

Wear App API Architecture

Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua

In AppListenerService.java, you can manage the callbacks from Node, Data and Message listeners

Page 32: Android Wear Presentation

Add Voice Action to Wear

Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua

You can trigger your app through voice actions

Page 33: Android Wear Presentation

Add Voice Action to Wear

Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua

Just add the intent filter to your WearActivitiy

<activity android:name=“MyWearActivity”><intent-filter>

<action android:name=“android.intent.action.SEND”/><category android:name =

“com.google.android.voicesearch.SELF_NOTE”/></intent-filter>

</activity>

Page 34: Android Wear Presentation

Add Voice Action to Wear

Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua

Available commands today (approval process similar to Google Glass)

More details: https://developer.android.com/training/wearables/apps/voice.html

Page 35: Android Wear Presentation

Add Voice Action to Wear

Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua

Alternatively, you can use “Start MyVoiceAction” to launch your app. Just declare in manifest under label.

<activity android:name=“MyWearActivity" Android:label=“MyVoiceAction"><intent-filter>

<action android:name="android.intent.action.MAIN" /><category

android:name="android.intent.category.LAUNCHER" /></intent-filter>

</activity>

Page 36: Android Wear Presentation

Add Voice Action to Wear

Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua

For additional input, say “Take a note”, follow by user voice input, you can get the voice input by calling startActivityForResult

// Create an intent that can start the Speech Recognizer activityprivate void displaySpeechRecognizer() {

Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);

intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,

RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);

startActivityForResult(intent, SPEECH_REQUEST_CODE);}

Page 37: Android Wear Presentation

What is Android Wear?

Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua

Code Demo Time

Page 38: Android Wear Presentation

Join GDG Singapore as member

• Keep up to date with Google products and technologies

• Make new friends that are also passionate about technology

• Interact with Googlers

• Access to selected exclusive Google events

• Find jobs and developers related to Google products

• Contribute to developer community

Learn more at www.gdg-sg.org/member

Page 39: Android Wear Presentation

Learn more at www.gdg-sg.org/member

Because pictures speak a thousand words

Page 40: Android Wear Presentation

Learn more at www.gdg-sg.org/member

For more membership details,

Get started today with just your email.

Visit http://bit.ly/gdg-sg-members