original source: https://developer.android.com/training/wearables/apps/index.html

Wearable Apps 개발의 기본

  • Watch apps use watch-specific APIs, where applicable (e.g., for circular layouts, wearable drawers, ambient mode, etc.).
  • Watch apps contain functionality appropriate to a watch.
  • Watch apps can access many standard Android APIs, but don’t support the following:
  1. android.webkit
  2. android.print
  3. android.app.backup
  4. android.appwidget
  5. android.hardware.usb

You can check if a watch supports a feature by calling hasSystemFeature() before using an API.

wearable app은 상황에 따라 두가지 모드로 들어갈수 있으며 두가지 모드를 다 지원하는 app을  always-on apps 이라고 한다. 

  • Interactive Use full color with fluid animation in this mode. The app is also responsive to input.
  • Ambient Render the screen with black and white graphics and do not present any input cues in this mode. This display mode is only supported on devices running Android 5.1 or higher.

original source : https://developer.android.com/training/wearables/notifications/compatibility.html

주의사항

  • Since a bridged notification needs to support both light (Wear1.x) and dark (Wear 2.0) backgrounds, We recommended that you don’t set color for bridged notifications. When Wear apps post local notifications, you can work around this by checking theAPI level of the device they’re running on and using an appropriate color for Wear 1.x and a different color for Wear 2.0.
  • Updated horizontal swipe gesture on a notification: To dismiss a notification in Wear 2.0, the user swipes horizontally in either direction. So if your notification instructs the user to swipe left or right, you must update the text of your notification.
  • Expanded notifications: To provide more information without requiring users to open your app on their phone, Wear 2.0 supports expanded notifications. So if you are currently using the addPage() method to provide additional text in your notification, you must update the code to useBigTextStyle in your expanded notification.

original source :https://developer.android.com/training/wearables/notifications/bridger.html#specifying-a-bridging-configuration-at-runtime

Bridging Mode for Notifications

handheld 기기와 wearable기기간에 공유되는 notification을 bridging notification이라고 한다.

개발자는 아래와 같은 방법으로 notification의 행동을 수정할수 있다.

  • Specifying a bridging configuration in the manifest file
  • Specifying a bridging configuration at runtime
  • Setting a dismissal ID so notification dismissals are synced across devices

Specifying a Bridging Configuration in the Manifest File

<application>
...
 <meta-data
   android:name="com.google.android.wearable.notificationBridgeMode"
   android:value="NO_BRIDGING" />
...
</application>

Specifying a Bridging Configuration at Runtime

create a BridgingConfig object and set it as shown in this section. manifest에서 정의된 것을 override한다.

BridgingManager.fromContext(context).setConfig(
 new BridgingConfig.Builder(context, false)
   .build());


Exempt notifications that are tagged

BridgingManager.fromContext(context).setConfig(
 new BridgingConfig.Builder(context, false)
   .addExcludedTags(Arrays.asList("foo", "bar", "baz"))
   .build());

      

           Setting a bridge tag

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
// ... set other fields ...
 .extend(
   new NotificationCompat.WearableExtender()
     .setBridgeTag("foo"));
 Notification notification = notificationBuilder.build();


Using a Dismissal ID to Sync Notification Dismissals

bridging mode를 수정하는 경우 여러기기들의 notification을 sync해야할 필요가 있는데 이를 수행하는 방법은 아래와 같다.

following methods of the NotificationCompat.WearableExtender class enable you to use dismissal IDs:

public WearableExtender setDismissalId(String dismissalId)
public String getDismissalId()

예시)

NotificationCompat.WearableExtender wearableExtender =
 new NotificationCompat.WearableExtender().setDismissalId("abc123");
Notification notification = new NotificationCompat.Builder(context)
// ... set other fields ...
 .extend(wearableExtender)
 .build();

Best Practices for Bridged Notifications

bridging notification이 전달되는 과정에 약간의 지연이 있음을 알고 wearable에 전달된 notification이 취소되고 그 와중에 사용자가 wearable에 전달된 notification을 클릭해서 반응한경우를 대비해야한다. 또 notification 여러개를 한번에 삭제하는 일이 없어야 한다.

Design Considerations

  • All notifications bridged from the paired phone to the Wear device use expanded notifications.
  • To learn when to use the different notification templates supported on Android Wear, read the Notifications patterns design guide.
  • To learn how to style your Wear notifications, read the Notifications style design guide.
  • If you have a chat messaging app, your notifications should use NotificationCompat.MessagingStyle. Wear uses the chat messages included in a MessagingStyle notification (see addMessage()) to provide a rich chat app-like experience in the expanded notification.
  • Add an inline action ( setHintDisplayActionInline(true)) within the notification stream to include a primary action that a user can quickly take on a notification. Examples of good use cases for an inline action within a notification stream include replying to a text message, stopping a fitnes activity, or archiving an email message.
  • Enable Smart Reply ( setAllowGeneratedReplies(true)) for your MessagingStyle notifications.

https://developer.android.com/training/wearables/notifications/creating.html#AddWearableFeatures

Creating a Notification for Wearables

  1. Create a Notification with the Notification Builder
  2. Construct Expanded notifications

Expanded notificationa의 사용이유

Expanded notifications provide substantial additional content and actions for each notification. When you specify additional content pages and actions for a notification 

사용자가 expanded notification을 보게되는 경우

  1. notification이 paired된 전화기로 부터 온경우
  2. notification에 

    contentIntent 가 정의 되지 않는 경우 (contentIntent 라는 것은 모든 notification에 기본적으로 들어가며 expanded notification의 경우는 추가하게된다.)

올바른 notificaton 작성 요령

  1. 전화기로 부터 wear기기로 오는 모든 notification은 expanded notification을 이용한다.
  2. 전화기에서 전화기로 전달되는 notification은 되도록이면 expanded를 사용하지 않는다.

Adding additional content to Expanded Notification

To show additional text in your expanded notification, use the BigTextStyle.

To add images in your expanded notification, you can use the BigPictureStyle. If you want to add more than one image in your expanded notification, use the addPage()method along with the BigPictureStyle.

Primary action

The expanded notification will contain one primary action, which is the first action in the notification unless a different action is specified using setContentAction().

Additional actions

To specify additional actions, use addAction() or addActions(). The action drawer of the expanded notification contains all available actions.

Add Notification Actions

In addition to the primary content action defined by setContentIntent(), you can add other actions by passing a PendingIntent to the addAction()method.

추가된 여러개의 action은 전화기에서는 버튼으로 표시되고 wearable기기에서는 content다음에 버튼으로 표기된다. reply action이 추가된경우 wearable에서는 voice input 이 가능하게 만들수도 있다.

image

Adding an Inline Action

Inline action allows users to take actions on a notification from within the notification stream card. On Wear, the inline action appears as an additional button displayed at the bottom of the notification.

image

Add Wearable Specific-features to a Notification

NotificationCompat.WearableExtender 를 사용하여 wearable 기기에 특화된 notification을 만들수 있다.

Specify Wearable-only Actions

wearable 기기에만 특정 actions를 적용하고 싶은 경우는 

NotificationCompat.Builder.addAction()대신에 WearableExtender.addAction()를 사용한다.

Adding voice input as a notification action

(voice input을 받을 수 있는 intent를 보내는 방법)

create an instance ofRemoteInput.Builder that you can add to your notification action.

Add Pre-defined Text Responses

Call setChoices() and pass it a string array.

image

Receiving the voice input as a string

To receive the user’s transcribed message in the activity you declared in the reply action’s intent, callgetResultsFromIntent(), passing in the “Reply” action’s intent. This method returns a Bundle that contains the text response. You can then query the Bundle to obtain the response.

Note: Starting in Android 8.0 (API level 26), you need to create notification channels for each type of notification you want to display

Android pop in animation

Close application and remove from recent apps/