Java Code Examples for com.google.android.gms.wearable.DataEvent#TYPE_CHANGED

The following examples show how to use com.google.android.gms.wearable.DataEvent#TYPE_CHANGED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From wearable with Apache License 2.0 6 votes vote down vote up
@Override
public void onDataChanged(@NonNull DataEventBuffer dataEventBuffer) {
    Log.d(TAG, "onDataChanged: " + dataEventBuffer);
    for (DataEvent event : dataEventBuffer) {
        if (event.getType() == DataEvent.TYPE_CHANGED) {
            String path = event.getDataItem().getUri().getPath();
            if (datapath.equals(path)) {
                DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem());
                String message = dataMapItem.getDataMap().getString("message");
                Log.v(TAG, "Wear activity received message: " + message);
                // Display message in UI
                mTextView.setText(message);

            } else {
                Log.e(TAG, "Unrecognized path: " + path);
            }
        } else if (event.getType() == DataEvent.TYPE_DELETED) {
            Log.v(TAG, "Data deleted : " + event.getDataItem().toString());
        } else {
            Log.e(TAG, "Unknown data event Type = " + event.getType());
        }
    }
}
 
Example 2
Source File: UARTCommandsActivity.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void onDataChanged(final DataEventBuffer dataEventBuffer) {
	for (final DataEvent event : dataEventBuffer) {
		final DataItem item = event.getDataItem();
		final long id = ContentUris.parseId(item.getUri());

		// Update the configuration only if ID matches
		if (id != configurationId)
			continue;

		// Configuration added or edited
		if (event.getType() == DataEvent.TYPE_CHANGED) {
			final DataMap dataMap = DataMapItem.fromDataItem(item).getDataMap();
			final UartConfiguration configuration = new UartConfiguration(dataMap, id);

			// Update UI on UI thread
			runOnUiThread(() -> adapter.setConfiguration(configuration));
		} else if (event.getType() == DataEvent.TYPE_DELETED) {
			// Configuration removed

			// Update UI on UI thread
			runOnUiThread(() -> adapter.setConfiguration(null));
		}
	}
}
 
Example 3
Source File: MainActivity.java    From wear with MIT License 6 votes vote down vote up
@Override
public void onDataChanged(DataEvent event) {
    if (DataEvent.TYPE_CHANGED == event.getType()) {
        DataMapItem item = DataMapItem.fromDataItem(event.getDataItem());
        Asset asset = item.getDataMap().getAsset(ASSET_KEY);

        ConnectionResult result = mGoogleApiClient
                .blockingConnect(TIMEOUT, TimeUnit.SECONDS);
        if (result.isSuccess()) {
            InputStream stream = Wearable.DataApi
                    .getFdForAsset(mGoogleApiClient, asset)
                    .await().getInputStream();
            if (null != asset) {
                Bitmap bitmap = BitmapFactory.decodeStream(stream);
                showAsset(bitmap);
            }
        }
    } else if (DataEvent.TYPE_DELETED == event.getType()) {
        hideAsset();
    }
}
 
Example 4
Source File: ConfigChangeListenerService.java    From FORMWatchFace with Apache License 2.0 6 votes vote down vote up
@Override
public void onDataChanged(final DataEventBuffer dataEvents) {
    ConfigHelper configHelper = new ConfigHelper(this);
    if (!configHelper.connect()) {
        return;
    }

    String localNodeId = configHelper.getLocalNodeId();

    for (DataEvent dataEvent : dataEvents) {
        if (dataEvent.getType() != DataEvent.TYPE_CHANGED) {
            continue;
        }

        Uri uri = dataEvent.getDataItem().getUri();
        if (!TextUtils.equals(uri.getHost(), localNodeId) &&
                uri.getPath().equals("/config")) {
            configHelper.readConfigSharedPrefsFromDataLayer();
        }
    }

    configHelper.disconnect();
}
 
Example 5
Source File: NotificationUpdateService.java    From AndroidWearable-Samples with Apache License 2.0 6 votes vote down vote up
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
    for (DataEvent dataEvent : dataEvents) {
        if (dataEvent.getType() == DataEvent.TYPE_CHANGED) {
            DataMap dataMap = DataMapItem.fromDataItem(dataEvent.getDataItem()).getDataMap();
            String content = dataMap.getString(Constants.KEY_CONTENT);
            String title = dataMap.getString(Constants.KEY_TITLE);
            if (Constants.WATCH_ONLY_PATH.equals(dataEvent.getDataItem().getUri().getPath())) {
                buildWearableOnlyNotification(title, content, false);
            } else if (Constants.BOTH_PATH.equals(dataEvent.getDataItem().getUri().getPath())) {
                buildWearableOnlyNotification(title, content, true);
            }
        } else if (dataEvent.getType() == DataEvent.TYPE_DELETED) {
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG, "DataItem deleted: " + dataEvent.getDataItem().getUri().getPath());
            }
            if (Constants.BOTH_PATH.equals(dataEvent.getDataItem().getUri().getPath())) {
                // Dismiss the corresponding notification
                ((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
                        .cancel(Constants.BOTH_ID);
            }
        }
    }
}
 
Example 6
Source File: WatchUpdaterService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onDataChanged(DataEventBuffer dataEvents) {//KS does not seem to get triggered; therefore use OnMessageReceived instead

    DataMap dataMap;

    for (DataEvent event : dataEvents) {

        if (event.getType() == DataEvent.TYPE_CHANGED) {

            String path = event.getDataItem().getUri().getPath();

            switch (path) {
                case WEARABLE_PREF_DATA_PATH:
                    dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
                    if (dataMap != null) {
                        Log.d(TAG, "onDataChanged WEARABLE_PREF_DATA_PATH dataMap=" + dataMap);
                        syncPrefData(dataMap);
                    }
                    break;
                default:
                    Log.d(TAG, "Unknown wearable path: " + path);
                    break;
            }
        }
    }
}
 
Example 7
Source File: WatchUpdaterService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onDataChanged(DataEventBuffer dataEvents) {//KS does not seem to get triggered; therefore use OnMessageReceived instead

    DataMap dataMap;

    for (DataEvent event : dataEvents) {

        if (event.getType() == DataEvent.TYPE_CHANGED) {

            String path = event.getDataItem().getUri().getPath();

            switch (path) {
                case WEARABLE_PREF_DATA_PATH:
                    dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
                    if (dataMap != null) {
                        Log.d(TAG, "onDataChanged WEARABLE_PREF_DATA_PATH dataMap=" + dataMap);
                        syncPrefData(dataMap);
                    }
                    break;
                default:
                    Log.d(TAG, "Unknown wearable path: " + path);
                    break;
            }
        }
    }
}
 
Example 8
Source File: ListenerService.java    From wear-os-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
    Log.d(TAG, "onDataChanged: " + dataEvents);

    for (DataEvent event : dataEvents) {
        if (event.getType() == DataEvent.TYPE_CHANGED
                && event.getDataItem() != null
                && Constants.ATTRACTION_PATH.equals(event.getDataItem().getUri().getPath())) {

            DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem());
            ArrayList<DataMap> attractionsData =
                    dataMapItem.getDataMap().getDataMapArrayList(Constants.EXTRA_ATTRACTIONS);
            showNotification(dataMapItem.getUri(), attractionsData);
        }
    }
}
 
Example 9
Source File: ComService.java    From android-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void onDataChanged(DataEventBuffer dataEventBuffer) {
    super.onDataChanged(dataEventBuffer);

    for (DataEvent dataEvent : dataEventBuffer) {

        if (dataEvent.getType() == DataEvent.TYPE_CHANGED) {

            //Check if the event path is for background color change?
            String path = dataEvent.getDataItem().getUri().getPath();
            if (path.equals("/bg_change")) {

                //get the value if new color
                DataMap dataMap = DataMapItem.fromDataItem(dataEvent.getDataItem()).getDataMap();
                String newColor = dataMap.getString("new_color", "#000000");

                //save the new back ground to preferences
                getSharedPreferences("settings", Context.MODE_PRIVATE)
                        .edit()
                        .putString("select_color", newColor)
                        .apply();

                //Broadcast to watch face service
                Intent intent = new Intent(ACTION_BG_COLOR_CHANGE);
                intent.putExtra(ARG_NEW_COLOR, newColor);
                LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
            }
        }
    }
}
 
Example 10
Source File: WearService.java    From android-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void onDataChanged(DataEventBuffer dataEventBuffer) {
    super.onDataChanged(dataEventBuffer);

    //This method will call while any changes in data map occurs from watch side
    //This is data map. So, message delivery is guaranteed.
    for (DataEvent dataEvent : dataEventBuffer) {

        //Check for only those data who changed
        if (dataEvent.getType() == DataEvent.TYPE_CHANGED) {
            DataMap dataMap = DataMapItem.fromDataItem(dataEvent.getDataItem()).getDataMap();

            //Check if the data map path matches with the step tracking status path
            String path = dataEvent.getDataItem().getUri().getPath();
            if (path.equals(STEP_TRACKING_STATUS_PATH)) {

                //Read the values
                boolean isTracking = dataMap.getBoolean("status");
                long timeStamp = dataMap.getLong("status-time");

                //send broadcast to update the UI in MainActivity based on the tracking status
                Intent intent = new Intent(TRACKING_STATUS_ACTION);
                intent.putExtra("status", isTracking);
                intent.putExtra("status-time", timeStamp);
                LocalBroadcastManager.getInstance(this).sendBroadcast(intent);

                Log.d("Tracking status: ", isTracking + " Time: " + timeStamp);
            }
        }
    }
}
 
Example 11
Source File: HomeListenerService.java    From AndroidWearable-Samples with Apache License 2.0 5 votes vote down vote up
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "onDataChanged: " + dataEvents + " for " + getPackageName());
    }
    for (DataEvent event : dataEvents) {
        if (event.getType() == DataEvent.TYPE_DELETED) {
            deleteDataItem(event.getDataItem());
        } else if (event.getType() == DataEvent.TYPE_CHANGED) {
            UpdateNotificationForDataItem(event.getDataItem());
        }
    }
    dataEvents.close();
}
 
Example 12
Source File: SoundAlarmListenerService.java    From android-FindMyPhone with Apache License 2.0 5 votes vote down vote up
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "onDataChanged: " + dataEvents + " for " + getPackageName());
    }
    for (DataEvent event : dataEvents) {
        if (event.getType() == DataEvent.TYPE_DELETED) {
            Log.i(TAG, event + " deleted");
        } else if (event.getType() == DataEvent.TYPE_CHANGED) {
            Boolean alarmOn =
                    DataMap.fromByteArray(event.getDataItem().getData()).get(FIELD_ALARM_ON);
            if (alarmOn) {
                mOrigVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_ALARM);
                mMediaPlayer.reset();
                // Sound alarm at max volume.
                mAudioManager.setStreamVolume(AudioManager.STREAM_ALARM, mMaxVolume, 0);
                mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
                try {
                    mMediaPlayer.setDataSource(getApplicationContext(), mAlarmSound);
                    mMediaPlayer.prepare();
                } catch (IOException e) {
                    Log.e(TAG, "Failed to prepare media player to play alarm.", e);
                }
                mMediaPlayer.start();
            } else {
                // Reset the alarm volume to the user's original setting.
                mAudioManager.setStreamVolume(AudioManager.STREAM_ALARM, mOrigVolume, 0);
                if (mMediaPlayer.isPlaying()) {
                    mMediaPlayer.stop();
                }
            }
        }
    }
}
 
Example 13
Source File: ListenerService.java    From ETSMobile-Android2 with Apache License 2.0 5 votes vote down vote up
@Override
public void onDataChanged(DataEventBuffer dataEvents) {

    Log.d(TAG, "onDataChanged: " + dataEvents);

    for (DataEvent event : dataEvents) {
        if (event.getType() == DataEvent.TYPE_CHANGED
                && event.getDataItem() != null
                && event.getDataItem().getUri().getPath().equals("/today_req")) {

            DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem());
            ArrayList<DataMap> seancesDataMapList = dataMapItem.getDataMap().getDataMapArrayList("list_seances");

            ArrayList<Seances> seances = new ArrayList<>();

            for (DataMap seanceDataMap : seancesDataMapList) {
                Seances seance = new Seances();
                seance.getData(seanceDataMap);
                seances.add(seance);
            }

            Intent intent = new Intent("seances_update");
            intent.putExtra("seances", seances);
            LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
        }
    }
    super.onDataChanged(dataEvents);
}
 
Example 14
Source File: ListenerService.java    From NightWatch with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDataChanged(DataEventBuffer dataEvents) {

    DataMap dataMap;

    for (DataEvent event : dataEvents) {

        if (event.getType() == DataEvent.TYPE_CHANGED) {


            String path = event.getDataItem().getUri().getPath();
            if (path.equals(OPEN_SETTINGS)) {
                //TODO: OpenSettings
                Intent intent = new Intent(this, NWPreferences.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);

            } else {

                dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();

                Intent messageIntent = new Intent();
                messageIntent.setAction(Intent.ACTION_SEND);
                messageIntent.putExtra("data", dataMap.toBundle());
                LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent);
            }
        }
    }
}
 
Example 15
Source File: ListenerService.java    From NightWatch with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDataChanged(DataEventBuffer dataEvents) {

    DataMap dataMap;

    for (DataEvent event : dataEvents) {

        if (event.getType() == DataEvent.TYPE_CHANGED) {


            String path = event.getDataItem().getUri().getPath();
            if (path.equals(OPEN_SETTINGS)) {
                //TODO: OpenSettings
                Intent intent = new Intent(this, NWPreferences.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);

            } else {

                dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();

                Intent messageIntent = new Intent();
                messageIntent.setAction(Intent.ACTION_SEND);
                messageIntent.putExtra("data", dataMap.toBundle());
                LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent);
            }
        }
    }
}
 
Example 16
Source File: MainActivity.java    From wear-os-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
    LOGD(TAG, "onDataChanged: " + dataEvents);

    for (DataEvent event : dataEvents) {
        if (event.getType() == DataEvent.TYPE_CHANGED) {
            mDataItemListAdapter.add(
                    new Event("DataItem Changed", event.getDataItem().toString()));
        } else if (event.getType() == DataEvent.TYPE_DELETED) {
            mDataItemListAdapter.add(
                    new Event("DataItem Deleted", event.getDataItem().toString()));
        }
    }
}
 
Example 17
Source File: OngoingNotificationListenerService.java    From WearOngoingNotificationSample with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
    public void onDataChanged(DataEventBuffer dataEvents) {
        final List<DataEvent> events = FreezableUtils.freezeIterable(dataEvents);
        dataEvents.close();

        if (!mGoogleApiClient.isConnected()) {
            ConnectionResult connectionResult = mGoogleApiClient
                    .blockingConnect(30, TimeUnit.SECONDS);
            if (!connectionResult.isSuccess()) {
                Log.e(TAG, "Service failed to connect to GoogleApiClient.");
                return;
            }
        }

        for (DataEvent event : events) {
            if (event.getType() == DataEvent.TYPE_CHANGED) {
                String path = event.getDataItem().getUri().getPath();
                if (Constants.PATH_NOTIFICATION.equals(path)) {
                    // Get the data out of the event
                    DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem());
                    final String title = dataMapItem.getDataMap().getString(Constants.KEY_TITLE);
                    Asset asset = dataMapItem.getDataMap().getAsset(Constants.KEY_IMAGE);

                    // Build the intent to display our custom notification
                    Intent notificationIntent = new Intent(this, NotificationActivity.class);
                    notificationIntent.putExtra(NotificationActivity.EXTRA_TITLE, title);
                    notificationIntent.putExtra(NotificationActivity.EXTRA_IMAGE, asset);
                    PendingIntent notificationPendingIntent = PendingIntent.getActivity(
                            this,
                            0,
                            notificationIntent,
                            PendingIntent.FLAG_UPDATE_CURRENT);

                    // Create the ongoing notification

                    // Use this for multipage notifications
//                    Notification secondPageNotification =
//                            new Notification.Builder(this)
//                                    .extend(new Notification.WearableExtender()
//                                            .setDisplayIntent(notificationPendingIntent))
//                                    .build();

                    Notification.Builder notificationBuilder =
                            new Notification.Builder(this)
                                    .setSmallIcon(R.drawable.ic_launcher)
                                    .extend(new Notification.WearableExtender()
                                            .setDisplayIntent(notificationPendingIntent)
//                                            .addPage(secondPageNotification)
                                    );

                    ((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
                            .notify(NOTIFICATION_ID, notificationBuilder.build());
                } else {
                    Log.d(TAG, "Unrecognized path: " + path);
                }
            }
        }
    }
 
Example 18
Source File: PixelWatchFace.java    From PixelWatchFace with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
  String TAG = "onDataChanged";
  Log.d(TAG, "Data changed");
  DataMap dataMap = new DataMap();
  for (DataEvent event : dataEvents) {
    if (event.getType() == DataEvent.TYPE_CHANGED) {
      // DataItem changed
      DataItem item = event.getDataItem();
      Log.d(TAG, "DataItem uri: " + item.getUri());

      if (item.getUri().getPath().compareTo("/settings") == 0) {
        Log.d(TAG, "Companion app changed a setting!");
        dataMap = DataMapItem.fromDataItem(item).getDataMap();
        Log.d(TAG, dataMap.toString());

        // handle legacy nested data map
        if (dataMap.containsKey("com.corvettecole.pixelwatchface")) {
          dataMap = dataMap.getDataMap("com.corvettecole.pixelwatchface");
        }

        Log.d(TAG, dataMap.toString());

        for (UpdatesRequired updateRequired : mSettings.updateSettings(dataMap)) {
          switch (updateRequired) {
            case WEATHER:
              initWeatherUpdater(true);
              break;
            case FONT:
              updateFontConfig();
              break;
          }
        }

        invalidate();// forces redraw
        //syncToPhone();
      } else if (item.getUri().getPath().compareTo("/requests") == 0) {
        if (dataMap.containsKey("settings-update")) {

        }
      }


    } else if (event.getType() == DataEvent.TYPE_DELETED) {
      // DataItem deleted
    }
  }
}
 
Example 19
Source File: MainActivity.java    From DronesWear with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
    for (DataEvent event : dataEvents) {

        DataItem dataItem = event.getDataItem();
        Message.MESSAGE_TYPE messageType = Message.getMessageType(dataItem);
        if (event.getType() == DataEvent.TYPE_DELETED) {
            switch (messageType) {
                case ACC:
                    synchronized (mDroneLock) {
                        if (mDrone != null && mUseWatchAccelero) {
                            mDrone.stopPiloting();
                        }

                    }
                    break;
                case JOYSTICK:
                    synchronized (mDroneLock) {
                        if (mDrone != null) {
                            mDrone.stopPiloting();
                        }

                    }
                    break;
            }
        } else if (event.getType() == DataEvent.TYPE_CHANGED) {
            switch (messageType) {
                case ACC:
                    synchronized (mDroneLock) {
                        if (mDrone != null && mUseWatchAccelero) {
                            AccelerometerData accelerometerData = Message.decodeAcceleroMessage(dataItem);
                            if (accelerometerData != null) {
                                mDrone.pilotWithAcceleroData(accelerometerData);
                            } else {
                                mDrone.stopPiloting();
                            }
                        }

                    }
                    break;
                case JOYSTICK:
                    synchronized (mDroneLock) {
                        if (mDrone != null) {
                            JoystickData joystickData = Message.decodeJoystickMessage(dataItem);
                            if (joystickData != null) {
                                mDrone.pilotWithJoystickData(joystickData);
                            } else {
                                mDrone.stopPiloting();
                            }
                        }

                    }
                    break;
                case ACTION:
                    if (mDrone != null) {
                        mDrone.sendAction();
                    }
                    break;
            }

        }
    }
}
 
Example 20
Source File: QuizListenerService.java    From android-Quiz with Apache License 2.0 4 votes vote down vote up
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
    GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this)
            .addApi(Wearable.API)
            .build();

    ConnectionResult connectionResult = googleApiClient.blockingConnect(CONNECT_TIMEOUT_MS,
            TimeUnit.MILLISECONDS);
    if (!connectionResult.isSuccess()) {
        Log.e(TAG, "QuizListenerService failed to connect to GoogleApiClient.");
        return;
    }

    for (DataEvent event : dataEvents) {
        if (event.getType() == DataEvent.TYPE_CHANGED) {
            DataItem dataItem = event.getDataItem();
            DataMap dataMap = DataMapItem.fromDataItem(dataItem).getDataMap();
            if (dataMap.getBoolean(QUESTION_WAS_ANSWERED)
                    || dataMap.getBoolean(QUESTION_WAS_DELETED)) {
                // Ignore the change in data; it is used in MainActivity to update
                // the question's status (i.e. was the answer right or wrong or left blank).
                continue;
            }
            String question = dataMap.getString(QUESTION);
            int questionIndex = dataMap.getInt(QUESTION_INDEX);
            int questionNum = questionIndex + 1;
            String[] answers = dataMap.getStringArray(ANSWERS);
            int correctAnswerIndex = dataMap.getInt(CORRECT_ANSWER_INDEX);
            Intent deleteOperation = new Intent(this, DeleteQuestionService.class);
            deleteOperation.setData(dataItem.getUri());
            PendingIntent deleteIntent = PendingIntent.getService(this, 0,
                    deleteOperation, PendingIntent.FLAG_UPDATE_CURRENT);
            // First page of notification contains question as Big Text.
            Notification.BigTextStyle bigTextStyle = new Notification.BigTextStyle()
                    .setBigContentTitle(getString(R.string.question, questionNum))
                    .bigText(question);
            Notification.Builder builder = new Notification.Builder(this)
                    .setStyle(bigTextStyle)
                    .setSmallIcon(R.drawable.ic_launcher)
                    .setLocalOnly(true)
                    .setDeleteIntent(deleteIntent);

            // Add answers as actions.
            Notification.WearableExtender wearableOptions = new Notification.WearableExtender();
            for (int i = 0; i < answers.length; i++) {
                Notification answerPage = new Notification.Builder(this)
                        .setContentTitle(question)
                        .setContentText(answers[i])
                        .extend(new Notification.WearableExtender()
                                .setContentAction(i))
                        .build();

                boolean correct = (i == correctAnswerIndex);
                Intent updateOperation = new Intent(this, UpdateQuestionService.class);
                // Give each intent a unique action.
                updateOperation.setAction("question_" + questionIndex + "_answer_" + i);
                updateOperation.setData(dataItem.getUri());
                updateOperation.putExtra(UpdateQuestionService.EXTRA_QUESTION_INDEX,
                        questionIndex);
                updateOperation.putExtra(UpdateQuestionService.EXTRA_QUESTION_CORRECT, correct);
                PendingIntent updateIntent = PendingIntent.getService(this, 0, updateOperation,
                        PendingIntent.FLAG_UPDATE_CURRENT);
                Notification.Action action = new Notification.Action.Builder(
                        questionNumToDrawableId.get(i), null, updateIntent)
                        .build();
                wearableOptions.addAction(action).addPage(answerPage);
            }
            builder.extend(wearableOptions);
            Notification notification = builder.build();
            ((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
                    .notify(questionIndex, notification);
        } else if (event.getType() == DataEvent.TYPE_DELETED) {
            Uri uri = event.getDataItem().getUri();
            // URI's are of the form "/question/0", "/question/1" etc.
            // We use the question index as the notification id.
            int notificationId = Integer.parseInt(uri.getLastPathSegment());
            ((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
                    .cancel(notificationId);
        }
        // Delete the quiz report, if it exists.
        ((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
                .cancel(QUIZ_REPORT_NOTIF_ID);
    }
    googleApiClient.disconnect();
}