字幕列表 影片播放 列印英文字幕 JUSTIN: Hi, my name is Justin Koh and I'm an engineer on the Android Wear team. I'm here today to tell you about how you can make your app ready for the wrist with Android Wear. Let's take a look at how developing for Android Wear is different than developing traditional Android apps. One key benefit of Android Wear is giving people the information they need right when they need it. We realize that your Android device already does a lot of this through notifications, so we decided to start by bringing those same notifications to your wrist. I'll show you what I mean. Here I have my Nexus 5. I've installed the Android Wear preview app on it, and I've paired it to my emulated device. I have a small app which creates notifications with different styles. Notice how the notification appears on Android Wear automatically. I can update the notification, and the changes are immediately bridged over. Even better, I can dismiss the notification from my Android Wear device and it'll disappear from my phone. This is a really powerful concept. This means that if your app posts notifications today it's already on your wrist. It's worth noting that all of this is possible thanks to the Notification Listener API that was added in Android 4.3. So let's talk about how to get started developing for Android Wear. First go to developer.android.com where you can sign up for the developer preview and browse the documentation. You should also download the system image from the SDK manager to create an Android virtual device with Android Wear. Finally, install the Android Wear preview app and run it on your Android phone that is connected to your emulator. At this point you'll have your development environment set up and ready to go. Let's look at some code for an app that invites people to events. It probably looks really familiar right? There isn't anything specific to Android Wear here. I'm just using the NotificationCompat class from the Android support library to show a notification. I've also added an action to my notification so I can tell my app that I'll be attending the event. This action becomes available on my wrist so I don't even have to take my phone out of my pocket to respond. Instead I just swipe over to the right and tap the action. That starts a service on the phone that can add the event to my calendar and then remove the notification. Note that I could have used the notification styles introduced in Android 4.1 such as Big Picture style to show a photo alongside the notification text. So that's really cool, but with great power comes great responsibility. Automatically bridging notifications to your wrist means it's extremely important that you be considerate of when and how you notify the user. First, note that Android Wear devices will not vibrate for every notification. That would get annoying really quickly. Only notifications which would vibrate or make a sound on the phone will buzz your wrist. Next, it's important that notifications be as contextually relevant as possible. For example, you can use the API's in Google Play services to set up a geofence and only post a notification when the user is at home. Or you could use the Activity Detection API to only send notifications when the user is biking. If you have an app that generates a lot of notifications, like a chat or email client, you should give your user control over when your notifications will make a sound or vibrate. Finally, you should take advantage of the notification priority field. There are several buckets, max, high, default, low, and min. Setting the proper priority helps the system show the most relevant information at the right time. For more on what makes a good notification see the design guidelines on developer.android.com. So that's one way you can begin getting your app ready for the wrist with Android Wear. By optimizing your app's notifications you'll be taking the first step to making your app more wrist friendly. There are more API's in the developer preview that will help you customize notifications when they appear on Android Wear devices. So check out the documentation in other DevBytes episodes for more on that. And make sure to look at the sample code in the developer preview and the UX guidelines on developer.android.com. Thanks and happy coding.
B2 中高級 DevBytes - Android Wear:開發者預覽 (DevBytes - Android Wear: Developer Preview) 122 11 王愷俊 發佈於 2021 年 01 月 14 日 更多分享 分享 收藏 回報 影片單字