• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

.google/23-Nov-2023-2014

Application/23-Nov-2023-1,704781

Shared/23-Nov-2023-13866

Wearable/23-Nov-2023-380223

gradle/wrapper/23-Nov-2023-66

screenshots/23-Nov-2023-

CONTRIB.mdD23-Nov-20231.6 KiB3627

CONTRIBUTING.mdD23-Nov-20231.5 KiB3627

LICENSED23-Nov-202311.1 KiB204170

README.mdD23-Nov-20234.4 KiB10075

build.gradleD23-Nov-202314 150

gradlewD23-Nov-20235 KiB165122

gradlew.batD23-Nov-20232.3 KiB9166

settings.gradleD23-Nov-202348 31

README.md

1
2Android SynchronizedNotifications Sample
3===================================
4
5A basic sample showing how to use simple or synchronized notifications.
6This allows users to dismiss events from either their phone or wearable device simultaneously.
7
8Introduction
9------------
10
11The [DataAPI][1] exposes an API for components to read or write data items and assets between
12the handhelds and wearables. A [DataItem][2] is synchronized across all devices in an Android Wear network.
13It is possible to set data items while not connected to any nodes. Those data items will be synchronized
14when the nodes eventually come online.
15
16This example presents three buttons that would trigger three different combinations of
17notifications on the handset and the watch:
18
191. The first button builds a simple local-only notification on the handset.
202. The second one creates a wearable-only notification by putting a data item in the shared data
21store and having a [com.google.android.gms.wearable.WearableListenerService][3] listen for
22that on the wearable.
233. The third one creates a local notification and a wearable notification by combining the above
24two. It, however, demonstrates how one can set things up so that the dismissal of one
25notification results in the dismissal of the other one.
26
27In the #2 and #3 items, the following code is used to synchronize the data between the handheld
28and the wearable devices using DataAPI.
29
30```java
31PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(path);
32putDataMapRequest.getDataMap().putString(Constants.KEY_CONTENT, content);
33putDataMapRequest.getDataMap().putString(Constants.KEY_TITLE, title);
34PutDataRequest request = putDataMapRequest.asPutDataRequest();
35Wearable.DataApi.putDataItem(mGoogleApiClient, request)
36        .setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
37            @Override
38            public void onResult(DataApi.DataItemResult dataItemResult) {
39                if (!dataItemResult.getStatus().isSuccess()) {
40                    Log.e(TAG, "buildWatchOnlyNotification(): Failed to set the data, "
41                            + "status: " + dataItemResult.getStatus().getStatusCode());
42                }
43            }
44        });
45```
46
47[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)
48[2]: http://developer.android.com/reference/com/google/android/gms/wearable/DataItem.html
49[3]: https://developer.android.com/reference/com/google/android/gms/wearable/WearableListenerService.html
50
51Pre-requisites
52--------------
53
54- Android SDK 27
55- Android Build Tools v27.0.2
56- Android Support Repository
57
58Screenshots
59-------------
60
61<img src="screenshots/different_notifications_phone.png" height="400" alt="Screenshot"/> <img src="screenshots/different_notifications_wearable.png" height="400" alt="Screenshot"/> <img src="screenshots/notification_options.png" height="400" alt="Screenshot"/> <img src="screenshots/watch_only_notification.png" height="400" alt="Screenshot"/>
62
63Getting Started
64---------------
65
66This sample uses the Gradle build system. To build this project, use the
67"gradlew build" command or use "Import Project" in Android Studio.
68
69Support
70-------
71
72- Google+ Community: https://plus.google.com/communities/105153134372062985968
73- Stack Overflow: http://stackoverflow.com/questions/tagged/android
74
75If you've found an error in this sample, please file an issue:
76https://github.com/googlesamples/android-SynchronizedNotifications
77
78Patches are encouraged, and may be submitted by forking this project and
79submitting a pull request through GitHub. Please see CONTRIBUTING.md for more details.
80
81License
82-------
83
84Copyright 2017 The Android Open Source Project, Inc.
85
86Licensed to the Apache Software Foundation (ASF) under one or more contributor
87license agreements.  See the NOTICE file distributed with this work for
88additional information regarding copyright ownership.  The ASF licenses this
89file to you under the Apache License, Version 2.0 (the "License"); you may not
90use this file except in compliance with the License.  You may obtain a copy of
91the License at
92
93http://www.apache.org/licenses/LICENSE-2.0
94
95Unless required by applicable law or agreed to in writing, software
96distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
97WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
98License for the specific language governing permissions and limitations under
99the License.
100