1page.title=Bridging Mode for Notifications
2meta.keywords="wear-preview"
3page.tags="wear-preview"
4
5@jd:body
6
7    <div id="qv-wrapper">
8      <div id="qv">
9        <ol>
10          <li>
11            <a href=
12            "#preventing_bridging_with_the_bridging_mode_feature">Preventing
13            Bridging with the Bridging Mode Feature</a>
14          </li>
15
16          <li>
17            <a href=
18            "#using_a_dismissal_id_to_sync_notification_dismissals">Using a
19            Dismissal ID to Sync Notification Dismissals</a>
20          </li>
21        </ol>
22      </div>
23    </div>
24
25    <p>
26      By default, notifications <a href=
27      "{@docRoot}training/wearables/notifications/index.html">are bridged
28      (shared)</a> from an app on a companion phone to the watch. If you build
29      a standalone watch app and have a companion phone app, they may duplicate
30      notifications. The Android Wear 2.0 Preview includes a Bridging mode
31      feature to handle this problem of repeated notifications.
32    </p>
33
34    <p>
35      With the Android Wear 2.0 Preview, developers can change the
36      behavior of notifications with the following:
37    </p>
38
39    <ul>
40      <li>Specifying in the standalone app's Android manifest file that
41      notifications from the corresponding phone app should not be
42      bridged to the watch
43      </li>
44
45      <li>Setting a dismissal ID so notification dismissals are synced across
46      devices
47      </li>
48    </ul>
49
50    <h2 id="preventing_bridging_with_the_bridging_mode_feature">
51      Preventing Bridging with the Bridging Mode Feature
52    </h2>
53
54    <p>
55      To prevent bridging of notifications from a phone app, you can use an
56      entry in the manifest file of the watch app (e.g. the standalone watch
57      app), as follows:
58    </p>
59
60    <pre>
61com.google.android.wearable.notificationBridgeMode
62    </pre>
63
64    <p>
65      Setting that entry to <code>NO_BRIDGING</code> will prevent bridging:
66    </p>
67
68    <pre>
69&lt;meta-data android:name="com.google.android.wearable.notificationBridgeMode"
70                   android:value="NO_BRIDGING" /&gt;
71</pre>
72    <p>
73      The default bridging behavior occurs if you do not include the entry or
74      if you specify a value of <code>BRIDGING</code> instead of
75      <code>NO_BRIDGING</code>.
76    </p>
77
78    <h3 id="existing_method_of_preventing_bridging">
79      Existing method of preventing bridging
80    </h3>
81
82    <p>
83      An existing way to prevent bridging is with the
84      <code>Notification.Builder</code> class; specify <code>true</code> in the
85      <a href=
86      "{@docRoot}reference/android/app/Notification.Builder.html#setLocalOnly(boolean)">
87      setLocalOnly</a> method.
88    </p>
89
90    <p>
91      However, this way to prevent bridging may not be preferable. For example,
92      if a user installs a phone app but not the corresponding watch app, the
93      <code>setLocalOnly</code> method could prevent the bridging of helpful
94      notifications. Additionally, users may have multiple paired watches and
95      the watch app may not be installed on all of them.
96    </p>
97
98    <p>
99      Thus, if bridging should be prevented when the watch app
100      is installed, use the <a href=
101      "#preventing_bridging_with_the_bridging_mode_feature">Bridging mode
102      feature</a>.
103    </p>
104
105    <h2 id="using_a_dismissal_id_to_sync_notification_dismissals">
106      Using a Dismissal ID to Sync Notification Dismissals
107    </h2>
108
109    <p>
110      If you prevent bridging with the Bridging mode feature, dismissals
111      (cancellations) of notifications are not synced across a user's devices.
112      However, the following methods of the <a href=
113      "{@docRoot}reference/android/support/v4/app/NotificationCompat.WearableExtender.html">
114      NotificationCompat.WearableExtender</a> class enable you to use dismissal
115      IDs:
116    </p>
117
118    <pre>
119public WearableExtender setDismissalId(String dismissalId)
120public String getDismissalId()
121    </pre>
122    <p>
123      To enable a dismissal to be synced, use the <code>setDismissalId()</code>
124      method. For each notification, pass a globally unique ID, as a string,
125      when you call the <code>setDismissalId()</code> method. When the
126      notification is dismissed, all other notifications with the same
127      dismissal ID are dismissed on the watch(es) and on the companion phone.
128      To retrieve a dismissal ID, use <code>getDismissalId()</code>.
129    </p>
130
131    <p>
132      In the following example, syncing of dismissals is enabled because a
133      globally unique ID is specified for a new notification:
134    </p>
135
136    <pre>
137NotificationCompat.WearableExtender wearableExtender =
138new NotificationCompat.WearableExtender().setDismissalId(“abc123”);
139Notification notification = new NotificationCompat.Builder(context)
140&lt;set other fields&gt;
141.extend(wearableExtender)
142.build();
143    </pre>
144    <p>
145      Dismissal IDs work if a watch is paired to an Android phone, but not if a
146      watch is paired to an iPhone.
147    </p>
148