Java Code Examples for com.google.android.gms.wearable.PutDataRequest#setUrgent()
The following examples show how to use
com.google.android.gms.wearable.PutDataRequest#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: 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 2
Source File: MainActivity.java From wear-os-samples with Apache License 2.0 | 6 votes |
/** * Sends the asset that was created from 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(); request.setUrgent(); Task<DataItem> dataItemTask = Wearable.getDataClient(this).putDataItem(request); dataItemTask.addOnSuccessListener( new OnSuccessListener<DataItem>() { @Override public void onSuccess(DataItem dataItem) { LOGD(TAG, "Sending image was successful: " + dataItem); } }); }
Example 3
Source File: SynchronizedNotificationsFragment.java From android-SynchronizedNotifications 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(); request.setUrgent(); 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 4
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 5
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 6
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 7
Source File: MainActivity.java From wearable with Apache License 2.0 | 6 votes |
/** * Sends the data. Since it specify a client, everyone who is listening to the path, will * get the data. */ 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 8
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 9
Source File: MessageReceiverService.java From ibm-wearables-android-sdk with Apache License 2.0 | 5 votes |
/** * Send the sensors data to the phone * @param dataMapRequest data map to send * @return send result */ @Override public PendingResult<DataApi.DataItemResult> sendData(PutDataMapRequest dataMapRequest) { PutDataRequest dataRequest = dataMapRequest.asPutDataRequest(); dataRequest.setUrgent(); return Wearable.DataApi.putDataItem(apiClient, dataRequest); }
Example 10
Source File: UpdateQuestionService.java From android-Quiz with Apache License 2.0 | 5 votes |
@Override protected void onHandleIntent(Intent intent) { mGoogleApiClient.blockingConnect(TIME_OUT_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(); // Update quiz status variables, which will be reflected on the phone. int questionIndex = intent.getIntExtra(EXTRA_QUESTION_INDEX, -1); boolean chosenAnswerCorrect = intent.getBooleanExtra(EXTRA_QUESTION_CORRECT, false); dataMap.putInt(QUESTION_INDEX, questionIndex); dataMap.putBoolean(CHOSEN_ANSWER_CORRECT, chosenAnswerCorrect); dataMap.putBoolean(QUESTION_WAS_ANSWERED, true); PutDataRequest request = putDataMapRequest.asPutDataRequest(); request.setUrgent(); Wearable.DataApi.putDataItem(mGoogleApiClient, request).await(); // Remove this question notification. ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).cancel(questionIndex); mGoogleApiClient.disconnect(); }
Example 11
Source File: MainActivity.java From android-Quiz with Apache License 2.0 | 5 votes |
public PutDataRequest toPutDataRequest() { PutDataMapRequest request = PutDataMapRequest.create("/question/" + questionIndex); DataMap dataMap = request.getDataMap(); dataMap.putString(QUESTION, question); dataMap.putInt(QUESTION_INDEX, questionIndex); dataMap.putStringArray(ANSWERS, answers); dataMap.putInt(CORRECT_ANSWER_INDEX, correctAnswerIndex); PutDataRequest putDataRequest = request.asPutDataRequest(); putDataRequest.setUrgent(); return putDataRequest; }
Example 12
Source File: UtilityService.java From wear-os-samples with Apache License 2.0 | 4 votes |
/** * Transfer the required data over to the wearable * @param attractions list of attraction data to transfer over */ private void sendDataToWearable(List<Attraction> attractions) { GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this) .addApi(Wearable.API) .build(); // It's OK to use blockingConnect() here as we are running in an // IntentService that executes work on a separate (background) thread. ConnectionResult connectionResult = googleApiClient.blockingConnect( Constants.GOOGLE_API_CLIENT_TIMEOUT_S, TimeUnit.SECONDS); // Limit attractions to send int count = attractions.size() > Constants.MAX_ATTRACTIONS ? Constants.MAX_ATTRACTIONS : attractions.size(); ArrayList<DataMap> attractionsData = new ArrayList<>(count); for (int i = 0; i < count; i++) { Attraction attraction = attractions.get(i); Bitmap image = null; Bitmap secondaryImage = null; try { // Fetch and resize attraction image bitmap image = Glide.with(this) .load(attraction.imageUrl) .asBitmap() .diskCacheStrategy(DiskCacheStrategy.SOURCE) .into(Constants.WEAR_IMAGE_SIZE_PARALLAX_WIDTH, Constants.WEAR_IMAGE_SIZE) .get(); secondaryImage = Glide.with(this) .load(attraction.secondaryImageUrl) .asBitmap() .diskCacheStrategy(DiskCacheStrategy.SOURCE) .into(Constants.WEAR_IMAGE_SIZE_PARALLAX_WIDTH, Constants.WEAR_IMAGE_SIZE) .get(); } catch (InterruptedException | ExecutionException e) { Log.e(TAG, "Exception loading bitmap from network"); } if (image != null && secondaryImage != null) { DataMap attractionData = new DataMap(); String distance = Utils.formatDistanceBetween( Utils.getLocation(this), attraction.location); attractionData.putString(Constants.EXTRA_TITLE, attraction.name); attractionData.putString(Constants.EXTRA_DESCRIPTION, attraction.description); attractionData.putDouble( Constants.EXTRA_LOCATION_LAT, attraction.location.latitude); attractionData.putDouble( Constants.EXTRA_LOCATION_LNG, attraction.location.longitude); attractionData.putString(Constants.EXTRA_DISTANCE, distance); attractionData.putString(Constants.EXTRA_CITY, attraction.city); attractionData.putAsset(Constants.EXTRA_IMAGE, Utils.createAssetFromBitmap(image)); attractionData.putAsset(Constants.EXTRA_IMAGE_SECONDARY, Utils.createAssetFromBitmap(secondaryImage)); attractionsData.add(attractionData); } } if (connectionResult.isSuccess() && googleApiClient.isConnected() && attractionsData.size() > 0) { PutDataMapRequest dataMap = PutDataMapRequest.create(Constants.ATTRACTION_PATH); dataMap.getDataMap().putDataMapArrayList(Constants.EXTRA_ATTRACTIONS, attractionsData); dataMap.getDataMap().putLong(Constants.EXTRA_TIMESTAMP, new Date().getTime()); PutDataRequest request = dataMap.asPutDataRequest(); request.setUrgent(); // Send the data over DataApi.DataItemResult result = Wearable.DataApi.putDataItem(googleApiClient, request).await(); if (!result.getStatus().isSuccess()) { Log.e(TAG, String.format("Error sending data using DataApi (error code = %d)", result.getStatus().getStatusCode())); } } else { Log.e(TAG, String.format(Constants.GOOGLE_API_CLIENT_ERROR_MSG, connectionResult.getErrorCode())); } googleApiClient.disconnect(); }