com.google.android.gms.wearable.PutDataMapRequest Java Examples
The following examples show how to use
com.google.android.gms.wearable.PutDataMapRequest.
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: DigitalWatchFaceUtil.java From wear-os-samples with Apache License 2.0 | 6 votes |
/** * Overwrites the current config {@link DataItem}'s {@link DataMap} with {@code newConfig}. * If the config DataItem doesn't exist, it's created. */ public static void putConfigDataItem(GoogleApiClient googleApiClient, DataMap newConfig, final Callable<Void> callable) { PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(PATH_WITH_FEATURE); putDataMapRequest.setUrgent(); DataMap configToPut = putDataMapRequest.getDataMap(); configToPut.putAll(newConfig); Wearable.DataApi.putDataItem(googleApiClient, putDataMapRequest.asPutDataRequest()) .setResultCallback(new ResultCallback<DataApi.DataItemResult>() { @Override public void onResult(DataApi.DataItemResult dataItemResult) { try{ if (callable != null) { callable.call(); } } catch (Exception e) { Log.e(TAG, "Finish callback failed.", e); } if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "putDataItem result status: " + dataItemResult.getStatus()); } } }); }
Example #2
Source File: MainActivity.java From WearOngoingNotificationSample with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void sendMessage() { if (mGoogleApiClient.isConnected()) { PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(Constants.PATH_NOTIFICATION); // Add data to the request putDataMapRequest.getDataMap().putString(Constants.KEY_TITLE, String.format("hello world! %d", count++)); Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); Asset asset = createAssetFromBitmap(icon); putDataMapRequest.getDataMap().putAsset(Constants.KEY_IMAGE, asset); PutDataRequest request = putDataMapRequest.asPutDataRequest(); Wearable.DataApi.putDataItem(mGoogleApiClient, request) .setResultCallback(new ResultCallback<DataApi.DataItemResult>() { @Override public void onResult(DataApi.DataItemResult dataItemResult) { Log.d(TAG, "putDataItem status: " + dataItemResult.getStatus().toString()); } }); } }
Example #3
Source File: DataManager.java From ibm-wearables-android-sdk with Apache License 2.0 | 6 votes |
/** * Create new Data Request and send it to the phone */ private void sendNextGestureData() { PutDataMapRequest dataMapRequest = getNewSensorsDataMapRequest(); DataMap dataMap = dataMapRequest.getDataMap(); List<GestureDataHolder.EventData> nextAccelerometerData = gestureDataHolder.pollNextAccelerometerData(); if (nextAccelerometerData.size() > 0){ dataMap.putDataMapArrayList("accelerometer", convertEventsToDataMapList(nextAccelerometerData)); } List<GestureDataHolder.EventData> nextGyroscopeData = gestureDataHolder.pollNextGyroscopeData(); if (nextGyroscopeData.size() > 0){ dataMap.putDataMapArrayList("gyroscope", convertEventsToDataMapList(nextGyroscopeData)); } dataSender.sendData(dataMapRequest); }
Example #4
Source File: WatchUpdaterService.java From xDrip with GNU General Public License v3.0 | 6 votes |
public static void sendTreatment(double carbs, double insulin, double bloodtest, String injectionJSON, double timeoffset, String timestring) { if ((googleApiClient != null) && (googleApiClient.isConnected())) { PutDataMapRequest dataMapRequest = PutDataMapRequest.create(WEARABLE_TREATMENT_PAYLOAD); //unique content dataMapRequest.setUrgent(); dataMapRequest.getDataMap().putDouble("timestamp", System.currentTimeMillis()); dataMapRequest.getDataMap().putDouble("carbs", carbs); dataMapRequest.getDataMap().putDouble("insulin", insulin); dataMapRequest.getDataMap().putDouble("bloodtest", bloodtest); dataMapRequest.getDataMap().putDouble("timeoffset", timeoffset); dataMapRequest.getDataMap().putString("timestring", timestring); dataMapRequest.getDataMap().putString("injectionJSON", injectionJSON); dataMapRequest.getDataMap().putBoolean("ismgdl", doMgdl(PreferenceManager.getDefaultSharedPreferences(xdrip.getAppContext()))); PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest(); Wearable.DataApi.putDataItem(googleApiClient, putDataRequest); } else { Log.e(TAG, "No connection to wearable available for send treatment!"); } }
Example #5
Source File: TrackActivity.java From android-samples with Apache License 2.0 | 6 votes |
/** * Send the current status of the step count tracking weather it is running or not. This message * is important and we should have guarantee of delivery to maintain the state of tracking status * on the phone. That is why we are using DataMap to communicate. So, if the phone is not connected * the message won't get lost. As soon as the phone connects, this status message will pass to the * phone application. * * @param isTracking true if the tracking is running */ private void sendTrackingStatusDataMap(boolean isTracking) { PutDataMapRequest dataMapRequest = PutDataMapRequest.create(STEP_TRACKING_STATUS_PATH); dataMapRequest.getDataMap().putBoolean("status", isTracking); dataMapRequest.getDataMap().putLong("status-time", System.currentTimeMillis()); PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest(); Wearable.DataApi.putDataItem(mGoogleApiClient, putDataRequest) .setResultCallback(new ResultCallback<DataApi.DataItemResult>() { @Override public void onResult(@NonNull DataApi.DataItemResult dataItemResult) { //check if the message is delivered? //If the status is failed, that means that the currently device is //not connected. The data will get deliver when phone gets connected to the watch. Log.d("Data saving", dataItemResult.getStatus().isSuccess() ? "Success" : "Failed"); } }); }
Example #6
Source File: WatchFaceConfigActivity.java From android-samples with Apache License 2.0 | 6 votes |
private void notifyWear(String newBgColor) { PutDataMapRequest dataMapRequest = PutDataMapRequest.create("/bg_change"); dataMapRequest.getDataMap().putString("new_color", newBgColor); PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest(); Wearable.DataApi.putDataItem(mGoogleApiClient, putDataRequest) .setResultCallback(new ResultCallback<DataApi.DataItemResult>() { @Override public void onResult(@NonNull DataApi.DataItemResult dataItemResult) { //check if the message is delivered? //If the status is failed, that means that the currently device is //not connected. The data will get deliver when phone gets connected to the watch. Log.d("Data saving", dataItemResult.getStatus().isSuccess() ? "Success" : "Failed"); } }); }
Example #7
Source File: MainActivity.java From AndroidWearable-Samples with Apache License 2.0 | 6 votes |
@Override public void onResult(DataApi.DataItemResult dataItemResult) { if (dataItemResult.getStatus().isSuccess()) { PutDataMapRequest request = PutDataMapRequest.createFromDataMapItem( DataMapItem.fromDataItem(dataItemResult.getDataItem())); DataMap dataMap = request.getDataMap(); dataMap.putBoolean(QUESTION_WAS_ANSWERED, false); dataMap.putBoolean(QUESTION_WAS_DELETED, false); if (!mHasQuestionBeenAsked && dataMap.getInt(QUESTION_INDEX) == 0) { // Ask the first question now. Wearable.DataApi.putDataItem(mGoogleApiClient, request.asPutDataRequest()); setHasQuestionBeenAsked(true); } else { // Enqueue future questions. mFutureQuestions.add(new Question(dataMap.getString(QUESTION), dataMap.getInt(QUESTION_INDEX), dataMap.getStringArray(ANSWERS), dataMap.getInt(CORRECT_ANSWER_INDEX))); } } else { Log.e(TAG, "Failed to reset data item " + dataItemResult.getDataItem().getUri()); } }
Example #8
Source File: WearableMainActivity.java From wear-os-samples with Apache License 2.0 | 6 votes |
private void addLocationEntry(double latitude, double longitude) { if (!mGpsPermissionApproved) { return; } mCalendar.setTimeInMillis(System.currentTimeMillis()); LocationEntry entry = new LocationEntry(mCalendar, latitude, longitude); String path = Constants.PATH + "/" + mCalendar.getTimeInMillis(); PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(path); putDataMapRequest.getDataMap().putDouble(Constants.KEY_LATITUDE, entry.latitude); putDataMapRequest.getDataMap().putDouble(Constants.KEY_LONGITUDE, entry.longitude); putDataMapRequest.getDataMap() .putLong(Constants.KEY_TIME, entry.calendar.getTimeInMillis()); PutDataRequest request = putDataMapRequest.asPutDataRequest(); request.setUrgent(); Task<DataItem> dataItemTask = Wearable.getDataClient(getApplicationContext()).putDataItem(request); dataItemTask.addOnSuccessListener(dataItem -> { Log.d(TAG, "Data successfully sent: " + dataItem.toString()); }); dataItemTask.addOnFailureListener(exception -> { Log.e(TAG, "AddPoint:onClick(): Failed to set the data, " + "exception: " + exception); }); }
Example #9
Source File: CalendarQueryService.java From AndroidWearable-Samples with Apache License 2.0 | 6 votes |
@Override protected void onHandleIntent(Intent intent) { mGoogleApiClient.blockingConnect(CONNECTION_TIME_OUT_MS, TimeUnit.MILLISECONDS); // Query calendar events in the next 24 hours. Time time = new Time(); time.setToNow(); long beginTime = time.toMillis(true); time.monthDay++; time.normalize(true); long endTime = time.normalize(true); List<Event> events = queryEvents(this, beginTime, endTime); for (Event event : events) { final PutDataMapRequest putDataMapRequest = event.toPutDataMapRequest(); if (mGoogleApiClient.isConnected()) { Wearable.DataApi.putDataItem( mGoogleApiClient, putDataMapRequest.asPutDataRequest()).await(); } else { Log.e(TAG, "Failed to send data item: " + putDataMapRequest + " - Client disconnected from Google Play Services"); } } mGoogleApiClient.disconnect(); }
Example #10
Source File: WatchUpdaterService.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
public static void sendTreatment(double carbs, double insulin, double bloodtest, String injectionJSON, double timeoffset, String timestring) { if ((googleApiClient != null) && (googleApiClient.isConnected())) { PutDataMapRequest dataMapRequest = PutDataMapRequest.create(WEARABLE_TREATMENT_PAYLOAD); //unique content dataMapRequest.setUrgent(); dataMapRequest.getDataMap().putDouble("timestamp", System.currentTimeMillis()); dataMapRequest.getDataMap().putDouble("carbs", carbs); dataMapRequest.getDataMap().putDouble("insulin", insulin); dataMapRequest.getDataMap().putDouble("bloodtest", bloodtest); dataMapRequest.getDataMap().putDouble("timeoffset", timeoffset); dataMapRequest.getDataMap().putString("timestring", timestring); dataMapRequest.getDataMap().putString("injectionJSON", injectionJSON); dataMapRequest.getDataMap().putBoolean("ismgdl", doMgdl(PreferenceManager.getDefaultSharedPreferences(xdrip.getAppContext()))); PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest(); Wearable.DataApi.putDataItem(googleApiClient, putDataRequest); } else { Log.e(TAG, "No connection to wearable available for send treatment!"); } }
Example #11
Source File: DeleteQuestionService.java From AndroidWearable-Samples with Apache License 2.0 | 6 votes |
@Override public void onHandleIntent(Intent intent) { mGoogleApiClient.blockingConnect(CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS); Uri dataItemUri = intent.getData(); if (!mGoogleApiClient.isConnected()) { Log.e(TAG, "Failed to update data item " + dataItemUri + " because client is disconnected from Google Play Services"); return; } DataApi.DataItemResult dataItemResult = Wearable.DataApi.getDataItem( mGoogleApiClient, dataItemUri).await(); PutDataMapRequest putDataMapRequest = PutDataMapRequest .createFromDataMapItem(DataMapItem.fromDataItem(dataItemResult.getDataItem())); DataMap dataMap = putDataMapRequest.getDataMap(); dataMap.putBoolean(QUESTION_WAS_DELETED, true); PutDataRequest request = putDataMapRequest.asPutDataRequest(); Wearable.DataApi.putDataItem(mGoogleApiClient, request).await(); mGoogleApiClient.disconnect(); }
Example #12
Source File: MainActivity.java From android-Quiz with Apache License 2.0 | 6 votes |
@Override public void onResult(DataApi.DataItemResult dataItemResult) { if (dataItemResult.getStatus().isSuccess()) { PutDataMapRequest request = PutDataMapRequest.createFromDataMapItem( DataMapItem.fromDataItem(dataItemResult.getDataItem())); DataMap dataMap = request.getDataMap(); dataMap.putBoolean(QUESTION_WAS_ANSWERED, false); dataMap.putBoolean(QUESTION_WAS_DELETED, false); if (!mHasQuestionBeenAsked && dataMap.getInt(QUESTION_INDEX) == 0) { // Ask the first question now. PutDataRequest putDataRequest = request.asPutDataRequest(); // Set to high priority in case it isn't already. putDataRequest.setUrgent(); Wearable.DataApi.putDataItem(mGoogleApiClient, putDataRequest); setHasQuestionBeenAsked(true); } else { // Enqueue future questions. mFutureQuestions.add(new Question(dataMap.getString(QUESTION), dataMap.getInt(QUESTION_INDEX), dataMap.getStringArray(ANSWERS), dataMap.getInt(CORRECT_ANSWER_INDEX))); } } else { Log.e(TAG, "Failed to reset data item " + dataItemResult.getDataItem().getUri()); } }
Example #13
Source File: MainActivity.java From AndroidWearable-Samples with Apache License 2.0 | 6 votes |
/** * Sends the asset that was created form the photo we took by adding it to the Data Item store. */ private void sendPhoto(Asset asset) { PutDataMapRequest dataMap = PutDataMapRequest.create(IMAGE_PATH); dataMap.getDataMap().putAsset(IMAGE_KEY, asset); dataMap.getDataMap().putLong("time", new Date().getTime()); PutDataRequest request = dataMap.asPutDataRequest(); Wearable.DataApi.putDataItem(mGoogleApiClient, request) .setResultCallback(new ResultCallback<DataItemResult>() { @Override public void onResult(DataItemResult dataItemResult) { LOGD(TAG, "Sending image was successful: " + dataItemResult.getStatus() .isSuccess()); } }); }
Example #14
Source File: MainActivity.java From AndroidWearable-Samples with Apache License 2.0 | 6 votes |
@Override public void run() { PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(COUNT_PATH); putDataMapRequest.getDataMap().putInt(COUNT_KEY, count++); PutDataRequest request = putDataMapRequest.asPutDataRequest(); LOGD(TAG, "Generating DataItem: " + request); if (!mGoogleApiClient.isConnected()) { return; } Wearable.DataApi.putDataItem(mGoogleApiClient, request) .setResultCallback(new ResultCallback<DataItemResult>() { @Override public void onResult(DataItemResult dataItemResult) { if (!dataItemResult.getStatus().isSuccess()) { Log.e(TAG, "ERROR: failed to putDataItem, status code: " + dataItemResult.getStatus().getStatusCode()); } } }); }
Example #15
Source File: PhoneActivity.java From AndroidWearable-Samples with Apache License 2.0 | 6 votes |
/** * Builds a DataItem that on the wearable will be interpreted as a request to show a * notification. The result will be a notification that only shows up on the wearable. */ private void buildWearableOnlyNotification(String title, String content, String path) { if (mGoogleApiClient.isConnected()) { PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(path); putDataMapRequest.getDataMap().putString(Constants.KEY_CONTENT, content); putDataMapRequest.getDataMap().putString(Constants.KEY_TITLE, title); PutDataRequest request = putDataMapRequest.asPutDataRequest(); Wearable.DataApi.putDataItem(mGoogleApiClient, request) .setResultCallback(new ResultCallback<DataApi.DataItemResult>() { @Override public void onResult(DataApi.DataItemResult dataItemResult) { if (!dataItemResult.getStatus().isSuccess()) { Log.e(TAG, "buildWatchOnlyNotification(): Failed to set the data, " + "status: " + dataItemResult.getStatus().getStatusCode()); } } }); } else { Log.e(TAG, "buildWearableOnlyNotification(): no Google API Client connection"); } }
Example #16
Source File: WatchUpdaterService.java From AndroidAPS with GNU Affero General Public License v3.0 | 6 votes |
private void sendPreferences() { if (googleApiClient.isConnected()) { boolean wearcontrol = SP.getBoolean("wearcontrol", false); PutDataMapRequest dataMapRequest = PutDataMapRequest.create(NEW_PREFERENCES_PATH); //unique content dataMapRequest.getDataMap().putLong("timestamp", System.currentTimeMillis()); dataMapRequest.getDataMap().putBoolean("wearcontrol", wearcontrol); PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest(); debugData("sendPreferences", putDataRequest); Wearable.DataApi.putDataItem(googleApiClient, putDataRequest); } else { Log.e("SendStatus", "No connection to wearable available!"); } }
Example #17
Source File: NotificationListenerService.java From wear-notify-for-reddit with Apache License 2.0 | 6 votes |
private void sendReplyToPhone(String text, String fullname, String toUser, String subject, boolean isDirectMessage) { PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(Constants.PATH_REPLY); putDataMapRequest.getDataMap().putLong("timestamp", System.currentTimeMillis()); putDataMapRequest.getDataMap().putString(Constants.PATH_KEY_MESSAGE_SUBJECT, subject); putDataMapRequest.getDataMap().putString(Constants.PATH_KEY_MESSAGE, text); putDataMapRequest.getDataMap().putString(Constants.PATH_KEY_POST_FULLNAME, fullname); putDataMapRequest.getDataMap().putString(Constants.PATH_KEY_MESSAGE_TO_USER, toUser); putDataMapRequest.getDataMap() .putBoolean(Constants.PATH_KEY_IS_DIRECT_MESSAGE, isDirectMessage); Wearable.DataApi.putDataItem(mGoogleApiClient, putDataMapRequest.asPutDataRequest()) .setResultCallback(new ResultCallback<DataApi.DataItemResult>() { @Override public void onResult(DataApi.DataItemResult dataItemResult) { logToPhone("sendReplyToPhone, putDataItem status: " + dataItemResult.getStatus() .toString()); } }); }
Example #18
Source File: DeviceClient.java From wearabird with MIT License | 6 votes |
public void sendSensorData(final int sensorType, final int accuracy, final long timestamp, final float[] values) { ConnectionManager.getInstance(context).sendMessage(new ConnectionManager.ConnectionManagerRunnable(context) { @Override public void send(GoogleApiClient googleApiClient) { PutDataMapRequest dataMap = PutDataMapRequest.create("/sensors/" + sensorType); dataMap.getDataMap().putInt(DataMapKeys.ACCURACY, accuracy); dataMap.getDataMap().putLong(DataMapKeys.TIMESTAMP, timestamp); dataMap.getDataMap().putFloatArray(DataMapKeys.VALUES, values); PutDataRequest putDataRequest = dataMap.asPutDataRequest(); Wearable.DataApi.putDataItem(googleApiClient, putDataRequest); } }); }
Example #19
Source File: WatchServices.java From WearPay with GNU General Public License v2.0 | 6 votes |
@DebugLog private void sendToWatch(String code) { Bitmap bitmapQR = EncodingHandlerUtils.createQRCode(code, 600); Bitmap bitmapBar = EncodingHandlerUtils.createBarcode(code, 600, 200); PutDataMapRequest dataMap = PutDataMapRequest.create(Common.PATH_QR_CODE); dataMap.getDataMap().putAsset(Common.KEY_QR_CODE, toAsset(bitmapQR)); dataMap.getDataMap().putAsset(Common.KEY_BAR_CODE, toAsset(bitmapBar)); PutDataRequest request = dataMap.asPutDataRequest(); Wearable.DataApi.putDataItem(mGoogleApiClient, request) .setResultCallback(new ResultCallback<DataApi.DataItemResult>() { @Override @DebugLog public void onResult(DataApi.DataItemResult dataItemResult) { if (dataItemResult.getStatus().isSuccess()) { System.out.println("发送成功"); } else { System.out.println("发送失败"); } } }); //sendMessageToAllNodes(Common.PATH_CODE, code.getBytes()); }
Example #20
Source File: WearService.java From TutosAndroidFrance with MIT License | 6 votes |
/** * Permet d'envoyer une image à la montre */ protected void sendImage(String url, int position) { //télécharge l'image Bitmap bitmap = getBitmapFromURL(url); if (bitmap != null) { Asset asset = createAssetFromBitmap(bitmap); //créé un emplacement mémoire "image/[url_image]" final PutDataMapRequest putDataMapRequest = PutDataMapRequest.create("/image/" + position); //ajoute la date de mise à jour, important pour que les données soient mises à jour putDataMapRequest.getDataMap().putString("timestamp", new Date().toString()); //ajoute l'image à la requête putDataMapRequest.getDataMap().putAsset("image", asset); //envoie la donnée à la montre if (mApiClient.isConnected()) Wearable.DataApi.putDataItem(mApiClient, putDataMapRequest.asPutDataRequest()); } }
Example #21
Source File: WearableUtil.java From APDE with GNU General Public License v2.0 | 6 votes |
public static void sendApkToWatch(Context context, File apkFile, final ResultCallback callback) { Uri apkUri = FileProvider.getUriForFile(context, "com.calsignlabs.apde.fileprovider", apkFile); Asset asset = Asset.createFromUri(apkUri); PutDataMapRequest dataMap = PutDataMapRequest.create("/apk"); dataMap.getDataMap().putAsset("apk", asset); dataMap.getDataMap().putLong("timestamp", System.currentTimeMillis()); PutDataRequest request = dataMap.asPutDataRequest(); request.setUrgent(); Task<DataItem> putTask = Wearable.getDataClient(context).putDataItem(request); putTask.addOnCompleteListener(new OnCompleteListener<DataItem>() { @Override public void onComplete(@NonNull Task<DataItem> task) { if (task.isSuccessful()) { callback.success(); } else { callback.failure(); } } }); }
Example #22
Source File: SendToDataLayerThread.java From xDrip-Experimental with GNU General Public License v3.0 | 6 votes |
@Override protected Void doInBackground(DataMap... params) { try { final NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(googleApiClient).await(15, TimeUnit.SECONDS); for (Node node : nodes.getNodes()) { for (DataMap dataMap : params) { PutDataMapRequest putDMR = PutDataMapRequest.create(path); putDMR.getDataMap().putAll(dataMap); PutDataRequest request = putDMR.asPutDataRequest(); DataApi.DataItemResult result = Wearable.DataApi.putDataItem(googleApiClient, request).await(15, TimeUnit.SECONDS); if (result.getStatus().isSuccess()) { Log.d(TAG, "DataMap: " + dataMap + " sent to: " + node.getDisplayName()); } else { Log.d(TAG, "ERROR: failed to send DataMap"); } } } } catch (Exception e) { Log.e(TAG, "Got exception sending data to wear: " + e.toString()); } return null; }
Example #23
Source File: SendToDataLayerThread.java From NightWatch with GNU General Public License v3.0 | 6 votes |
@Override protected Void doInBackground(DataMap... params) { NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(googleApiClient).await(); for (Node node : nodes.getNodes()) { for (DataMap dataMap : params) { PutDataMapRequest putDMR = PutDataMapRequest.create(path); putDMR.getDataMap().putAll(dataMap); PutDataRequest request = putDMR.asPutDataRequest(); DataApi.DataItemResult result = Wearable.DataApi.putDataItem(googleApiClient,request).await(); if (result.getStatus().isSuccess()) { Log.d("SendDataThread", "DataMap: " + dataMap + " sent to: " + node.getDisplayName()); } else { Log.d("SendDataThread", "ERROR: failed to send DataMap"); } } } return null; }
Example #24
Source File: MainActivity.java From wearable with Apache License 2.0 | 6 votes |
/** * Sends the data, note this is a broadcast, so we will get the message as well. */ private void sendData(String message) { PutDataMapRequest dataMap = PutDataMapRequest.create(datapath); dataMap.getDataMap().putString("message", message); PutDataRequest request = dataMap.asPutDataRequest(); request.setUrgent(); Task<DataItem> dataItemTask = Wearable.getDataClient(this).putDataItem(request); dataItemTask .addOnSuccessListener(new OnSuccessListener<DataItem>() { @Override public void onSuccess(DataItem dataItem) { Log.d(TAG, "Sending message was successful: " + dataItem); } }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { Log.e(TAG, "Sending message failed: " + e); } }) ; }
Example #25
Source File: WearableService.java From sms-ticket with Apache License 2.0 | 6 votes |
private void sendSmsNotification(Ticket t, int status) { DebugLog.d("Send ticket to wear" + t.toString()); final DataMap dataMap = new DataMap(); dataMap.putLong("id", t.getId()); dataMap.putLong("city_id", t.getCityId()); dataMap.putString("city", t.getCity()); dataMap.putInt("status", status); dataMap.putString("hash", t.getHash()); dataMap.putString("text", t.getText()); dataMap.putLong("valid_from", t.getValidFrom().toMillis(true)); dataMap.putLong("valid_to", t.getValidTo().toMillis(true)); dataMap.putLong("notification_id", t.getNotificationId()); PutDataMapRequest data = PutDataMapRequest.createWithAutoAppendedId("/notification"); data.getDataMap().putDataMap("notification", dataMap); syncDataItem(data); }
Example #26
Source File: Emmet.java From Wear-Emmet with Apache License 2.0 | 6 votes |
private void sendDataMapRequest(PutDataMapRequest request) { Wearable.DataApi.putDataItem(mApiClient, request.asPutDataRequest()).setResultCallback( new ResultCallback<DataApi.DataItemResult>() { @Override public void onResult(DataApi.DataItemResult dataItemResult) { if (dataItemResult.getStatus().isSuccess()) { if (ENABLE_LOG) Log.d(TAG, "sent"); } else { if (ENABLE_LOG) Log.d(TAG, "send error"); } } } ); }
Example #27
Source File: UARTConfigurationSynchronizer.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Synchronizes the UART configurations between handheld and wearables. * Call this when configuration has been created or altered. * @return pending result */ public PendingResult<DataApi.DataItemResult> onConfigurationAddedOrEdited(final long id, final UartConfiguration configuration) { if (!hasConnectedApi()) return null; final PutDataMapRequest mapRequest = PutDataMapRequest.create(Constants.UART.CONFIGURATIONS + "/" + id); final DataMap map = mapRequest.getDataMap(); map.putString(Constants.UART.Configuration.NAME, configuration.getName()); final ArrayList<DataMap> commands = new ArrayList<>(UartConfiguration.COMMANDS_COUNT); for (Command command : configuration.getCommands()) { if (command != null && command.isActive()) { final DataMap item = new DataMap(); item.putInt(Constants.UART.Configuration.Command.ICON_ID, command.getIconIndex()); item.putString(Constants.UART.Configuration.Command.MESSAGE, command.getCommand()); item.putInt(Constants.UART.Configuration.Command.EOL, command.getEolIndex()); commands.add(item); } } map.putDataMapArrayList(Constants.UART.Configuration.COMMANDS, commands); final PutDataRequest request = mapRequest.asPutDataRequest(); return Wearable.DataApi.putDataItem(googleApiClient, request); }
Example #28
Source File: SendToDataLayerThread.java From NightWatch with GNU General Public License v3.0 | 6 votes |
@Override protected Void doInBackground(DataMap... params) { NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(googleApiClient).await(); for (Node node : nodes.getNodes()) { for (DataMap dataMap : params) { PutDataMapRequest putDMR = PutDataMapRequest.create(path); putDMR.getDataMap().putAll(dataMap); PutDataRequest request = putDMR.asPutDataRequest(); DataApi.DataItemResult result = Wearable.DataApi.putDataItem(googleApiClient,request).await(); if (result.getStatus().isSuccess()) { Log.d("SendDataThread", "DataMap: " + dataMap + " sent to: " + node.getDisplayName()); } else { Log.d("SendDataThread", "ERROR: failed to send DataMap"); } } } return null; }
Example #29
Source File: DeleteQuestionService.java From android-Quiz with Apache License 2.0 | 6 votes |
@Override public void onHandleIntent(Intent intent) { mGoogleApiClient.blockingConnect(CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS); Uri dataItemUri = intent.getData(); if (!mGoogleApiClient.isConnected()) { Log.e(TAG, "Failed to update data item " + dataItemUri + " because client is disconnected from Google Play Services"); return; } DataApi.DataItemResult dataItemResult = Wearable.DataApi.getDataItem( mGoogleApiClient, dataItemUri).await(); PutDataMapRequest putDataMapRequest = PutDataMapRequest .createFromDataMapItem(DataMapItem.fromDataItem(dataItemResult.getDataItem())); DataMap dataMap = putDataMapRequest.getDataMap(); dataMap.putBoolean(QUESTION_WAS_DELETED, true); PutDataRequest request = putDataMapRequest.asPutDataRequest(); request.setUrgent(); Wearable.DataApi.putDataItem(mGoogleApiClient, request).await(); mGoogleApiClient.disconnect(); }
Example #30
Source File: DeviceClient.java From SensorDashboard with Apache License 2.0 | 6 votes |
private void sendSensorDataInBackground(int sensorType, int accuracy, long timestamp, float[] values) { if (sensorType == filterId) { Log.i(TAG, "Sensor " + sensorType + " = " + Arrays.toString(values)); } else { Log.d(TAG, "Sensor " + sensorType + " = " + Arrays.toString(values)); } PutDataMapRequest dataMap = PutDataMapRequest.create("/sensors/" + sensorType); dataMap.getDataMap().putInt(DataMapKeys.ACCURACY, accuracy); dataMap.getDataMap().putLong(DataMapKeys.TIMESTAMP, timestamp); dataMap.getDataMap().putFloatArray(DataMapKeys.VALUES, values); PutDataRequest putDataRequest = dataMap.asPutDataRequest(); send(putDataRequest); }