Java Code Examples for com.google.android.gms.wearable.PutDataMapRequest#setUrgent()
The following examples show how to use
com.google.android.gms.wearable.PutDataMapRequest#setUrgent() .
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: WatchUpdaterService.java From xDrip with GNU General Public License v3.0 | 6 votes |
private void sendDataReceived(String path, String notification, long timeOfLastEntry, String type, long watch_syncLogsRequested) {//KS Log.d(TAG, "sendDataReceived timeOfLastEntry=" + JoH.dateTimeText(timeOfLastEntry) + " Path=" + path); forceGoogleApiConnect(); if (googleApiClient.isConnected()) { PutDataMapRequest dataMapRequest = PutDataMapRequest.create(path); dataMapRequest.setUrgent(); dataMapRequest.getDataMap().putDouble("timestamp", System.currentTimeMillis()); dataMapRequest.getDataMap().putLong("timeOfLastEntry", timeOfLastEntry); dataMapRequest.getDataMap().putLong("syncLogsRequested", watch_syncLogsRequested); dataMapRequest.getDataMap().putString("type", type); dataMapRequest.getDataMap().putString("msg", notification); PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest(); Wearable.DataApi.putDataItem(googleApiClient, putDataRequest); } else { Log.e(TAG, "sendDataReceived No connection to wearable available!"); } }
Example 3
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 4
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 5
Source File: WatchUpdaterService.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
private void sendDataReceived(String path, String notification, long timeOfLastEntry, String type, long watch_syncLogsRequested) {//KS Log.d(TAG, "sendDataReceived timeOfLastEntry=" + JoH.dateTimeText(timeOfLastEntry) + " Path=" + path); forceGoogleApiConnect(); if (googleApiClient.isConnected()) { PutDataMapRequest dataMapRequest = PutDataMapRequest.create(path); dataMapRequest.setUrgent(); dataMapRequest.getDataMap().putDouble("timestamp", System.currentTimeMillis()); dataMapRequest.getDataMap().putLong("timeOfLastEntry", timeOfLastEntry); dataMapRequest.getDataMap().putLong("syncLogsRequested", watch_syncLogsRequested); dataMapRequest.getDataMap().putString("type", type); dataMapRequest.getDataMap().putString("msg", notification); PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest(); Wearable.DataApi.putDataItem(googleApiClient, putDataRequest); } else { Log.e(TAG, "sendDataReceived No connection to wearable available!"); } }
Example 6
Source File: PixelWatchFace.java From PixelWatchFace with GNU General Public License v3.0 | 5 votes |
private void syncToPhone() { String TAG = "syncToPhone"; DataClient mDataClient = Wearable.getDataClient(getApplicationContext()); PutDataMapRequest putDataMapReq = PutDataMapRequest.create("/watch-settings"); putDataMapReq.setUrgent(); Task<DataItem> putDataTask = mDataClient.putDataItem(putDataMapReq.asPutDataRequest()); if (putDataTask.isSuccessful()) { Log.d(TAG, "Current stats synced to phone"); } }
Example 7
Source File: WearableApi.java From LibreAlarm with GNU General Public License v3.0 | 5 votes |
private static boolean sendData(GoogleApiClient client, PutDataMapRequest putDataMapReq, ResultCallback<DataApi.DataItemResult> listener) { if (client.isConnected()) { Log.i(TAG, "update settings"); putDataMapReq.setUrgent(); PutDataRequest putDataReq = putDataMapReq.asPutDataRequest(); PendingResult<DataApi.DataItemResult> pR = Wearable.DataApi.putDataItem(client, putDataReq); if (listener != null) pR.setResultCallback(listener); return true; } return false; }
Example 8
Source File: WatchUpdaterService.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
private void sendBlob(String path, final byte[] blob) { forceGoogleApiConnect(); if (googleApiClient.isConnected()) { final Asset asset = Asset.createFromBytes(blob); Log.d(TAG, "sendBlob asset size: " + asset.getData().length); final PutDataMapRequest request = PutDataMapRequest.create(path); request.getDataMap().putLong("time", new Date().getTime()); request.getDataMap().putByteArray("asset", blob); request.setUrgent(); final PendingResult result = Wearable.DataApi.putDataItem(googleApiClient, request.asPutDataRequest()); result.setResultCallback(new ResultCallback<DataApi.DataItemResult>() { @Override public void onResult(DataApi.DataItemResult sendMessageResult) { if (!sendMessageResult.getStatus().isSuccess()) { UserError.Log.e(TAG, "ERROR: failed to sendblob Status=" + sendMessageResult.getStatus().getStatusMessage()); } else { UserError.Log.i(TAG, "Sendblob Status=: " + sendMessageResult.getStatus().getStatusMessage()); } } }); Log.d(TAG, "sendBlob: Sending asset of size " + blob.length); } else { Log.e(TAG, "sendBlob: No connection to wearable available!"); } }
Example 9
Source File: WatchUpdaterService.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
private void sendRequestExtra(String path, String key, byte[] value) { forceGoogleApiConnect(); if (googleApiClient.isConnected()) { PutDataMapRequest dataMapRequest = PutDataMapRequest.create(path); dataMapRequest.getDataMap().putDouble("timestamp", System.currentTimeMillis()); dataMapRequest.getDataMap().putByteArray(key, value); PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest(); dataMapRequest.setUrgent(); Wearable.DataApi.putDataItem(googleApiClient, putDataRequest); Log.d(TAG, "Sending bytes path: " + path + " " + value.length); } else { Log.e("sendRequestExtra", "No connection to wearable available!"); } }
Example 10
Source File: WatchUpdaterService.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
private void sendNotification(String path, String notification) {//KS add args forceGoogleApiConnect(); if (googleApiClient.isConnected()) { Log.d(TAG, "sendNotification Notification=" + notification + " Path=" + path); PutDataMapRequest dataMapRequest = PutDataMapRequest.create(path); //unique content dataMapRequest.setUrgent(); dataMapRequest.getDataMap().putDouble("timestamp", System.currentTimeMillis()); dataMapRequest.getDataMap().putString(notification, notification); PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest(); Wearable.DataApi.putDataItem(googleApiClient, putDataRequest); } else { Log.e(TAG, "sendNotification No connection to wearable available!"); } }
Example 11
Source File: WatchUpdaterService.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
public static void sendWearLocalToast(String msg, int length) { if ((googleApiClient != null) && (googleApiClient.isConnected())) { PutDataMapRequest dataMapRequest = PutDataMapRequest.create(WEARABLE_TOAST_LOCAL_NOTIFICATON); dataMapRequest.setUrgent(); dataMapRequest.getDataMap().putDouble("timestamp", System.currentTimeMillis()); dataMapRequest.getDataMap().putInt("length", length); dataMapRequest.getDataMap().putString("msg", msg); PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest(); Wearable.DataApi.putDataItem(googleApiClient, putDataRequest); } else { Log.e(TAG, "No connection to wearable available for toast! " + msg); } }
Example 12
Source File: WatchUpdaterService.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
public static void sendWearToast(String msg, int length) { if ((googleApiClient != null) && (googleApiClient.isConnected())) { PutDataMapRequest dataMapRequest = PutDataMapRequest.create(WEARABLE_TOAST_NOTIFICATON); dataMapRequest.setUrgent(); dataMapRequest.getDataMap().putDouble("timestamp", System.currentTimeMillis()); dataMapRequest.getDataMap().putInt("length", length); dataMapRequest.getDataMap().putString("msg", msg); PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest(); Wearable.DataApi.putDataItem(googleApiClient, putDataRequest); } else { Log.e(TAG, "No connection to wearable available for toast! " + msg); } }
Example 13
Source File: WatchUpdaterService.java From xDrip with GNU General Public License v3.0 | 5 votes |
private void sendBlob(String path, final byte[] blob) { forceGoogleApiConnect(); if (googleApiClient.isConnected()) { final Asset asset = Asset.createFromBytes(blob); Log.d(TAG, "sendBlob asset size: " + asset.getData().length); final PutDataMapRequest request = PutDataMapRequest.create(path); request.getDataMap().putLong("time", new Date().getTime()); request.getDataMap().putByteArray("asset", blob); request.setUrgent(); final PendingResult result = Wearable.DataApi.putDataItem(googleApiClient, request.asPutDataRequest()); result.setResultCallback(new ResultCallback<DataApi.DataItemResult>() { @Override public void onResult(DataApi.DataItemResult sendMessageResult) { if (!sendMessageResult.getStatus().isSuccess()) { UserError.Log.e(TAG, "ERROR: failed to sendblob Status=" + sendMessageResult.getStatus().getStatusMessage()); } else { UserError.Log.i(TAG, "Sendblob Status=: " + sendMessageResult.getStatus().getStatusMessage()); } } }); Log.d(TAG, "sendBlob: Sending asset of size " + blob.length); } else { Log.e(TAG, "sendBlob: No connection to wearable available!"); } }
Example 14
Source File: WatchUpdaterService.java From xDrip with GNU General Public License v3.0 | 5 votes |
private void sendRequestExtra(String path, String key, byte[] value) { forceGoogleApiConnect(); if (googleApiClient.isConnected()) { PutDataMapRequest dataMapRequest = PutDataMapRequest.create(path); dataMapRequest.getDataMap().putDouble("timestamp", System.currentTimeMillis()); dataMapRequest.getDataMap().putByteArray(key, value); PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest(); dataMapRequest.setUrgent(); Wearable.DataApi.putDataItem(googleApiClient, putDataRequest); Log.d(TAG, "Sending bytes path: " + path + " " + value.length); } else { Log.e("sendRequestExtra", "No connection to wearable available!"); } }
Example 15
Source File: WatchUpdaterService.java From xDrip with GNU General Public License v3.0 | 5 votes |
private void sendNotification(String path, String notification) {//KS add args forceGoogleApiConnect(); if (googleApiClient.isConnected()) { Log.d(TAG, "sendNotification Notification=" + notification + " Path=" + path); PutDataMapRequest dataMapRequest = PutDataMapRequest.create(path); //unique content dataMapRequest.setUrgent(); dataMapRequest.getDataMap().putDouble("timestamp", System.currentTimeMillis()); dataMapRequest.getDataMap().putString(notification, notification); PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest(); Wearable.DataApi.putDataItem(googleApiClient, putDataRequest); } else { Log.e(TAG, "sendNotification No connection to wearable available!"); } }
Example 16
Source File: WatchUpdaterService.java From xDrip with GNU General Public License v3.0 | 5 votes |
public static void sendWearLocalToast(String msg, int length) { if ((googleApiClient != null) && (googleApiClient.isConnected())) { PutDataMapRequest dataMapRequest = PutDataMapRequest.create(WEARABLE_TOAST_LOCAL_NOTIFICATON); dataMapRequest.setUrgent(); dataMapRequest.getDataMap().putDouble("timestamp", System.currentTimeMillis()); dataMapRequest.getDataMap().putInt("length", length); dataMapRequest.getDataMap().putString("msg", msg); PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest(); Wearable.DataApi.putDataItem(googleApiClient, putDataRequest); } else { Log.e(TAG, "No connection to wearable available for toast! " + msg); } }
Example 17
Source File: WatchUpdaterService.java From xDrip with GNU General Public License v3.0 | 5 votes |
public static void sendWearToast(String msg, int length) { if ((googleApiClient != null) && (googleApiClient.isConnected())) { PutDataMapRequest dataMapRequest = PutDataMapRequest.create(WEARABLE_TOAST_NOTIFICATON); dataMapRequest.setUrgent(); dataMapRequest.getDataMap().putDouble("timestamp", System.currentTimeMillis()); dataMapRequest.getDataMap().putInt("length", length); dataMapRequest.getDataMap().putString("msg", msg); PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest(); Wearable.DataApi.putDataItem(googleApiClient, putDataRequest); } else { Log.e(TAG, "No connection to wearable available for toast! " + msg); } }
Example 18
Source File: MainActivity.java From PixelWatchFace with GNU General Public License v3.0 | 5 votes |
private void syncToWear() { //Toast.makeText(this, "something changed, syncing to watch", Toast.LENGTH_SHORT).show(); Snackbar.make(findViewById(android.R.id.content), "Syncing to watch...", Snackbar.LENGTH_SHORT) .show(); loadPreferences(); String TAG = "syncToWear"; DataClient mDataClient = Wearable.getDataClient(this); PutDataMapRequest putDataMapReq = PutDataMapRequest.create("/settings"); /* Reference DataMap retrieval code on the WearOS app mShowTemperature = dataMap.getBoolean("show_temperature"); mUseCelsius = dataMap.getBoolean("use_celsius"); mShowWeather = dataMap.getBoolean("show_weather"); */ putDataMapReq.getDataMap().putLong("timestamp", System.currentTimeMillis()); putDataMapReq.getDataMap().putBoolean("show_temperature", showTemperature); putDataMapReq.getDataMap().putBoolean("use_celsius", useCelsius); putDataMapReq.getDataMap().putBoolean("show_weather", showWeather); putDataMapReq.getDataMap().putBoolean("show_temperature_decimal", showTemperatureDecimalPoint); putDataMapReq.getDataMap().putBoolean("use_thin", useThin); putDataMapReq.getDataMap().putBoolean("use_thin_ambient", useThinAmbient); putDataMapReq.getDataMap().putBoolean("use_gray_info_ambient", useGrayInfoAmbient); putDataMapReq.getDataMap().putBoolean("show_infobar_ambient", showInfoBarAmbient); putDataMapReq.getDataMap().putString("dark_sky_api_key", darkSkyAPIKey); putDataMapReq.getDataMap().putBoolean("use_dark_sky", useDarkSky); putDataMapReq.getDataMap().putBoolean("show_battery", showBattery); putDataMapReq.getDataMap().putBoolean("show_wear_icon", showWearIcon); putDataMapReq.getDataMap().putBoolean("advanced", advanced); putDataMapReq.setUrgent(); Task<DataItem> putDataTask = mDataClient.putDataItem(putDataMapReq.asPutDataRequest()); if (putDataTask.isSuccessful()) { Log.d(TAG, "Settings synced to wearable"); } }
Example 19
Source File: FindPhoneService.java From android-FindMyPhone with Apache License 2.0 | 4 votes |
@Override protected void onHandleIntent(Intent intent) { mGoogleApiClient.blockingConnect(CONNECTION_TIME_OUT_MS, TimeUnit.MILLISECONDS); if (Log.isLoggable(TAG, Log.VERBOSE)) { Log.v(TAG, "FindPhoneService.onHandleIntent"); } if (mGoogleApiClient.isConnected()) { // Set the alarm off by default. boolean alarmOn = false; if (intent.getAction().equals(ACTION_TOGGLE_ALARM)) { // Get current state of the alarm. DataItemBuffer result = Wearable.DataApi.getDataItems(mGoogleApiClient).await(); try { if (result.getStatus().isSuccess()) { if (result.getCount() == 1) { alarmOn = DataMap.fromByteArray(result.get(0).getData()) .getBoolean(FIELD_ALARM_ON, false); } else { Log.e(TAG, "Unexpected number of DataItems found.\n" + "\tExpected: 1\n" + "\tActual: " + result.getCount()); } } else if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "onHandleIntent: failed to get current alarm state"); } } finally { result.release(); } // Toggle alarm. alarmOn = !alarmOn; // Change notification text based on new value of alarmOn. String notificationText = alarmOn ? getString(R.string.turn_alarm_off) : getString(R.string.turn_alarm_on); FindPhoneActivity.updateNotification(this, notificationText); } // Use alarmOn boolean to update the DataItem - phone will respond accordingly // when it receives the change. PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(PATH_SOUND_ALARM); putDataMapRequest.getDataMap().putBoolean(FIELD_ALARM_ON, alarmOn); putDataMapRequest.setUrgent(); Wearable.DataApi.putDataItem(mGoogleApiClient, putDataMapRequest.asPutDataRequest()) .await(); } else { Log.e(TAG, "Failed to toggle alarm on phone - Client disconnected from Google Play " + "Services"); } mGoogleApiClient.disconnect(); }
Example 20
Source File: GeofenceTransitionsIntentService.java From android-Geofencing with Apache License 2.0 | 4 votes |
/** * Handles incoming intents. * @param intent The Intent sent by Location Services. This Intent is provided to Location * Services (inside a PendingIntent) when addGeofences() is called. */ @Override protected void onHandleIntent(Intent intent) { GeofencingEvent geoFenceEvent = GeofencingEvent.fromIntent(intent); if (geoFenceEvent.hasError()) { int errorCode = geoFenceEvent.getErrorCode(); Log.e(TAG, "Location Services error: " + errorCode); } else { int transitionType = geoFenceEvent.getGeofenceTransition(); if (Geofence.GEOFENCE_TRANSITION_ENTER == transitionType) { // Connect to the Google Api service in preparation for sending a DataItem. mGoogleApiClient.blockingConnect(CONNECTION_TIME_OUT_MS, TimeUnit.MILLISECONDS); // Get the geofence id triggered. Note that only one geofence can be triggered at a // time in this example, but in some cases you might want to consider the full list // of geofences triggered. String triggeredGeoFenceId = geoFenceEvent.getTriggeringGeofences().get(0) .getRequestId(); // Create a DataItem with this geofence's id. The wearable can use this to create // a notification. final PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(GEOFENCE_DATA_ITEM_PATH); putDataMapRequest.getDataMap().putString(KEY_GEOFENCE_ID, triggeredGeoFenceId); putDataMapRequest.setUrgent(); 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"); } Toast.makeText(this, getString(R.string.entering_geofence), Toast.LENGTH_SHORT).show(); mGoogleApiClient.disconnect(); } else if (Geofence.GEOFENCE_TRANSITION_EXIT == transitionType) { // Delete the data item when leaving a geofence region. mGoogleApiClient.blockingConnect(CONNECTION_TIME_OUT_MS, TimeUnit.MILLISECONDS); Wearable.DataApi.deleteDataItems(mGoogleApiClient, GEOFENCE_DATA_ITEM_URI).await(); showToast(this, R.string.exiting_geofence); mGoogleApiClient.disconnect(); } } }