Skip to content
This repository has been archived by the owner on Mar 24, 2022. It is now read-only.

Commit

Permalink
Make sure notifications are displayed.
Browse files Browse the repository at this point in the history
In NotificationWithOpenActivityOnWearableAction, the data items sent between the phone and the wearable were not unique, resulting in a situation where only the first notification would be displayed on the watch. Fixes #4.
  • Loading branch information
peterfriese committed Aug 8, 2014
1 parent d7ed144 commit 55a6f0f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Expand Up @@ -3,6 +3,7 @@
public class Constants {

public static final String NOTIFICATION_PATH = "/notification";
public static final String NOTIFICATION_TIMESTAMP = "timestamp";
public static final String NOTIFICATION_TITLE = "title";
public static final String NOTIFICATION_CONTENT = "content";

Expand Down
@@ -1,7 +1,6 @@
package de.peterfriese.notificationwithopenactivityonwearableaction;

import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
Expand All @@ -20,8 +19,6 @@

import de.peterfriese.notificationwithopenactivityonwearableaction.common.Constants;

import static com.google.android.gms.wearable.PutDataRequest.WEAR_URI_SCHEME;

public class MyActivity extends Activity {

private static final String TAG = "PhoneActivity";
Expand Down Expand Up @@ -81,6 +78,11 @@ private String now() {
private void sendNotification() {
if (mGoogleApiClient.isConnected()) {
PutDataMapRequest dataMapRequest = PutDataMapRequest.create(Constants.NOTIFICATION_PATH);
// Make sure the data item is unique. Usually, this will not be required, as the payload
// (in this case the title and the content of the notification) will be different for almost all
// situations. However, in this example, the text and the content are always the same, so we need
// to disambiguate the data item by adding a field that contains teh current time in milliseconds.
dataMapRequest.getDataMap().putDouble(Constants.NOTIFICATION_TIMESTAMP, System.currentTimeMillis());
dataMapRequest.getDataMap().putString(Constants.NOTIFICATION_TITLE, "This is the title");
dataMapRequest.getDataMap().putString(Constants.NOTIFICATION_CONTENT, "This is a notification with some text.");
PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest();
Expand Down

0 comments on commit 55a6f0f

Please sign in to comment.