Introduction to Android Wear
Talk by Chua Zi Yonghttps://plus.google.com/+ZiYongChua
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
Learn more at www.gdg-sg.org/member
Because pictures speak a thousand words
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
What is Android Wear?
Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua
What is Android Wear?
Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua
Notifications
Apps on Wear
Android Fit
What is Android Wear?
Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua
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
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
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
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
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
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
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)
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);
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
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
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
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);
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
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
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
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
Wear App API Architecture
Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua
Phone APK Wear APK
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
Wear App API Architecture
Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua
Wear App API Architecture
Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua
Wear App API Architecture
Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua
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();
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>
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
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
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>
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
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>
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);}
What is Android Wear?
Introduction to Android Wear by Chua Zi Yong - https://plus.google.com/+ZiYongChua
Code Demo Time
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
Learn more at www.gdg-sg.org/member
Because pictures speak a thousand words
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
Recommended