Java Code Examples for com.google.android.gms.wearable.DataEvent#getType()

The following examples show how to use com.google.android.gms.wearable.DataEvent#getType() . 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: HomeListenerService.java    From AndroidWearable-Samples with Apache License 2.0 6 votes vote down vote up
/**
 * Listen for DataItems added/deleted from the geofence service running on the companion.
 */
@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) {
            cancelNotificationForDataItem(event.getDataItem());
        } else if (event.getType() == DataEvent.TYPE_CHANGED) {
            // The user has entered a geofence - post a notification!
            String geofenceId = DataMap.fromByteArray(event.getDataItem().getData())
                    .getString(KEY_GEOFENCE_ID);
            postNotificationForGeofenceId(geofenceId, event.getDataItem().getUri());
        }
    }
    dataEvents.close();
}
 
Example 2
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 3
Source File: MainActivity.java    From DaVinci with Apache License 2.0 6 votes vote down vote up
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
    for (DataEvent event : dataEvents) {

        if (event.getType() == DataEvent.TYPE_CHANGED && event.getDataItem().getUri().getPath().startsWith("/elements/")) {
            DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem());
            List<DataMap> elementsDataMap = dataMapItem.getDataMap().getDataMapArrayList("/list/");

            if (elementList == null || elementList.isEmpty()) {
                elementList = new ArrayList<>();

                for (DataMap dataMap : elementsDataMap) {
                    elementList.add(getElement(dataMap));
                }

                startMainScreen();
            }

        }
    }
}
 
Example 4
Source File: NotificationUpdateService.java    From android-SynchronizedNotifications 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.WATCH_ONLY_ID);
            }
        }
    }
}
 
Example 5
Source File: WatchFaceCompanionConfigActivity.java    From american-sunsets-watch-face with Apache License 2.0 6 votes vote down vote up
@Override // DataApi.DataListener
public void onDataChanged(DataEventBuffer dataEvents) {
    for (DataEvent dataEvent : dataEvents) {
        if (dataEvent.getType() != DataEvent.TYPE_CHANGED) {
            continue;
        }

        DataItem dataItem = dataEvent.getDataItem();
        if (!dataItem.getUri().getPath().equals(SunsetsWatchFaceUtil.PATH_WITH_FEATURE)) {
            continue;
        }

        DataMapItem dataMapItem = DataMapItem.fromDataItem(dataItem);
        DataMap config = dataMapItem.getDataMap();
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "Config DataItem updated:" + config);
        }
        updateUiForConfigDataMap(config);
    }
}
 
Example 6
Source File: HomeListenerService.java    From android-Geofencing with Apache License 2.0 6 votes vote down vote up
/**
 * Listen for DataItems added/deleted from the geofence service running on the companion.
 */
@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) {
            cancelNotificationForDataItem(event.getDataItem());
        } else if (event.getType() == DataEvent.TYPE_CHANGED) {
            // The user has entered a geofence - post a notification!
            String geofenceId = DataMap.fromByteArray(event.getDataItem().getData())
                    .getString(KEY_GEOFENCE_ID);
            postNotificationForGeofenceId(geofenceId, event.getDataItem().getUri());
        }
    }
}
 
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: 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 9
Source File: MainActivity.java    From DronesWear with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
    for (DataEvent event : dataEvents) {
        if (event.getType() == DataEvent.TYPE_CHANGED) {
            DataItem dataItem = event.getDataItem();
            switch (Message.getMessageType(dataItem)) {
                case ACTION_TYPE:
                    int productAction = Message.decodeActionTypeMessage(dataItem);
                    onActionTypeChanged(productAction);
                    break;
                case INTERACTION_TYPE:
                    int interactionType = Message.decodeInteractionTypeMessage(dataItem);
                    onInteractionTypeChanged(interactionType);
                    break;
            }

        }
    }
}
 
Example 10
Source File: MainActivity.java    From wearable with Apache License 2.0 6 votes vote down vote up
/**
 * Receives the data, note since we are using the same data base, we will also receive
 * data that we sent as well.  Likely should add some kind of id number to datamap, so it
 * can tell between mobile device and wear device.  or this maybe the functionality you want.
 */
@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
                logthis(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 11
Source File: SensorReceiverService.java    From wearabird with MIT License 6 votes vote down vote up
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
	for (DataEvent dataEvent : dataEvents) {
		if (dataEvent.getType() == DataEvent.TYPE_CHANGED) {
			DataItem dataItem = dataEvent.getDataItem();
			Uri uri = dataItem.getUri();
			String path = uri.getPath();

			if (path.startsWith("/sensors/")) {
				unpackSensorData(
						Integer.parseInt(uri.getLastPathSegment()),
						DataMapItem.fromDataItem(dataItem).getDataMap()
				);
			}
		}
	}
}
 
Example 12
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) {
    Log.d(TAG, "onDataChanged(): " + dataEvents);

    for (DataEvent event : dataEvents) {
        if (event.getType() == DataEvent.TYPE_CHANGED) {
            String path = event.getDataItem().getUri().getPath();
            if (DataLayerListenerService.IMAGE_PATH.equals(path)) {
                DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem());
                Asset photoAsset =
                        dataMapItem.getDataMap().getAsset(DataLayerListenerService.IMAGE_KEY);
                // Loads image on background thread.
                new LoadBitmapAsyncTask().execute(photoAsset);

            } else if (DataLayerListenerService.COUNT_PATH.equals(path)) {
                Log.d(TAG, "Data Changed for COUNT_PATH");
                mCustomRecyclerAdapter.appendToDataEventLog(
                        "DataItem Changed", event.getDataItem().toString());
            } else {
                Log.d(TAG, "Unrecognized path: " + path);
            }

        } else if (event.getType() == DataEvent.TYPE_DELETED) {
            mCustomRecyclerAdapter.appendToDataEventLog(
                    "DataItem Deleted", event.getDataItem().toString());

        } else {
            mCustomRecyclerAdapter.appendToDataEventLog(
                    "Unknown data event type", "Type = " + event.getType());
        }
    }
}
 
Example 13
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 14
Source File: CrashReport.java    From AndroidWearCrashReport with Apache License 2.0 5 votes vote down vote up
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
    for (DataEvent event : dataEvents) {
        if (event.getType() == DataEvent.TYPE_CHANGED &&
                event.getDataItem().getUri().getPath().contains("/EXCEPTION")) {

            //A new Exception has been received
            DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem());

            //Get the exception
            byte[] serializedException = dataMapItem.getDataMap().getByteArray("ex");
            Throwable throwable = (Throwable) Utils.deserializeObject(serializedException);

            //Send it with the listener
            if (throwable != null) {

                if (onCrashListener != null) {
                    currentCrashInfo = new CrashInfo.Builder(throwable)
                            .fingerprint(dataMapItem.getDataMap().getString("fingerprint"))
                            .manufacturer(dataMapItem.getDataMap().getString("manufacturer"))
                            .model(dataMapItem.getDataMap().getString("model"))
                            .product(dataMapItem.getDataMap().getString("product"))
                            .versionCode(dataMapItem.getDataMap().getInt("versionCode"))
                            .versionName(dataMapItem.getDataMap().getString("versionName"))
                            .build();
                    onCrashListener.onCrashReceived(currentCrashInfo);
                }
                this.currentException = throwable;
            }
        }
    }
}
 
Example 15
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 16
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 17
Source File: MainActivity.java    From AndroidWearable-Samples with Apache License 2.0 5 votes vote down vote up
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
    LOGD(TAG, "onDataChanged(): " + dataEvents);

    final List<DataEvent> events = FreezableUtils.freezeIterable(dataEvents);
    dataEvents.close();
    for (DataEvent event : events) {
        if (event.getType() == DataEvent.TYPE_CHANGED) {
            String path = event.getDataItem().getUri().getPath();
            if (DataLayerListenerService.IMAGE_PATH.equals(path)) {
                DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem());
                Asset photo = dataMapItem.getDataMap()
                        .getAsset(DataLayerListenerService.IMAGE_KEY);
                final Bitmap bitmap = loadBitmapFromAsset(mGoogleApiClient, photo);
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        Log.d(TAG, "Setting background image..");
                        mLayout.setBackground(new BitmapDrawable(getResources(), bitmap));
                    }
                });

            } else if (DataLayerListenerService.COUNT_PATH.equals(path)) {
                LOGD(TAG, "Data Changed for COUNT_PATH");
                generateEvent("DataItem Changed", event.getDataItem().toString());
            } else {
                LOGD(TAG, "Unrecognized path: " + path);
            }

        } else if (event.getType() == DataEvent.TYPE_DELETED) {
            generateEvent("DataItem Deleted", event.getDataItem().toString());
        } else {
            generateEvent("Unknown data event type", "Type = " + event.getType());
        }
    }
}
 
Example 18
Source File: DismissListener.java    From android-SynchronizedNotifications with Apache License 2.0 5 votes vote down vote up
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
    for (DataEvent dataEvent : dataEvents) {
        if (dataEvent.getType() == DataEvent.TYPE_DELETED) {
            if (Constants.BOTH_PATH.equals(dataEvent.getDataItem().getUri().getPath())) {
                // notification on the phone should be dismissed
                NotificationManagerCompat.from(this).cancel(Constants.BOTH_ID);
            }
        }
    }
}
 
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();
}