Home | History | Annotate | Download | only in SynchronizedNotifications
      1 <?xml version="1.0" encoding="UTF-8"?>
      2 <!--
      3  Copyright 2013 The Android Open Source Project
      4 
      5  Licensed under the Apache License, Version 2.0 (the "License");
      6  you may not use this file except in compliance with the License.
      7  You may obtain a copy of the License at
      8 
      9      http://www.apache.org/licenses/LICENSE-2.0
     10 
     11  Unless required by applicable law or agreed to in writing, software
     12  distributed under the License is distributed on an "AS IS" BASIS,
     13  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  See the License for the specific language governing permissions and
     15  limitations under the License.
     16 -->
     17 
     18 
     19 
     20 <sample>
     21     <name>SynchronizedNotifications</name>
     22     <group>Wearable</group>
     23     <package>com.example.android.wearable.synchronizednotifications</package>
     24 
     25     <minSdk>18</minSdk>
     26     <targetSdkVersion>23</targetSdkVersion>
     27     <targetSdkVersionWear>22</targetSdkVersionWear>
     28 
     29     <wearable>
     30         <has_handheld_app>true</has_handheld_app>
     31     </wearable>
     32 
     33     <strings>
     34         <intro>
     35             <![CDATA[
     36             This sample creates simple or synchronized notifications on a
     37             device and an Android Wear watch.
     38             ]]>
     39         </intro>
     40     </strings>
     41 
     42     <template src="base"/>
     43     <template src="SimpleView"/>
     44     <template src="WearPlusShared"/>
     45     <common src="logger"/>
     46     <common src="activities"/>
     47 
     48     <metadata>
     49         <status>PUBLISHED</status>
     50         <categories>Wearable</categories>
     51         <technologies>Android</technologies>
     52         <languages>Java</languages>
     53         <solutions>Mobile</solutions>
     54         <level>INTERMEDIATE</level>
     55         <icon>screenshots/web-icon.png</icon>
     56         <screenshots>
     57             <img>screenshots/different_notifications_phone.png</img>
     58             <img>screenshots/different_notifications_wearable.png</img>
     59             <img>screenshots/notification_options.png</img>
     60             <img>screenshots/watch_only_notification.png</img>
     61         </screenshots>
     62         <api_refs>
     63             <android>com.google.android.gms.wearable.DataApi</android>
     64             <android>com.google.android.gms.wearable.Wearable</android>
     65             <android>com.google.android.gms.wearable.WearableListenerService</android>
     66         </api_refs>
     67 
     68         <description>
     69 <![CDATA[
     70 A basic sample showing how to use simple or synchronized notifications.
     71 This allows users to dismiss events from either their phone or wearable device simultaneously.
     72 ]]>
     73         </description>
     74 
     75         <intro>
     76 <![CDATA[
     77 The [DataAPI][1] exposes an API for components to read or write data items and assets between
     78 the handhelds and wearables. A [DataItem][2] is synchronized across all devices in an Android Wear network.
     79 It is possible to set data items while not connected to any nodes. Those data items will be synchronized
     80 when the nodes eventually come online.
     81 
     82 This example presents three buttons that would trigger three different combinations of
     83 notifications on the handset and the watch:
     84 
     85 1. The first button builds a simple local-only notification on the handset.
     86 2. The second one creates a wearable-only notification by putting a data item in the shared data
     87 store and having a [com.google.android.gms.wearable.WearableListenerService][3] listen for
     88 that on the wearable.
     89 3. The third one creates a local notification and a wearable notification by combining the above
     90 two. It, however, demonstrates how one can set things up so that the dismissal of one
     91 notification results in the dismissal of the other one.
     92 
     93 In the #2 and #3 items, the following code is used to synchronize the data between the handheld
     94 and the wearable devices using DataAPI.
     95 
     96 ```java
     97 PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(path);
     98 putDataMapRequest.getDataMap().putString(Constants.KEY_CONTENT, content);
     99 putDataMapRequest.getDataMap().putString(Constants.KEY_TITLE, title);
    100 PutDataRequest request = putDataMapRequest.asPutDataRequest();
    101 Wearable.DataApi.putDataItem(mGoogleApiClient, request)
    102         .setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
    103             @Override
    104             public void onResult(DataApi.DataItemResult dataItemResult) {
    105                 if (!dataItemResult.getStatus().isSuccess()) {
    106                     Log.e(TAG, "buildWatchOnlyNotification(): Failed to set the data, "
    107                             + "status: " + dataItemResult.getStatus().getStatusCode());
    108                 }
    109             }
    110         });
    111 ```
    112 
    113 [1]: http://developer.android.com/reference/com/google/android/gms/wearable/DataApi.html#putDataItem(com.google.android.gms.common.api.GoogleApiClient%2C%20com.google.android.gms.wearable.PutDataRequest)
    114 [2]: http://developer.android.com/reference/com/google/android/gms/wearable/DataItem.html
    115 [3]: https://developer.android.com/reference/com/google/android/gms/wearable/WearableListenerService.html
    116 ]]>
    117         </intro>
    118     </metadata>
    119 </sample>
    120