本文整理汇总了Java中com.google.android.gms.wearable.PutDataMapRequest.create方法的典型用法代码示例。如果您正苦于以下问题:Java PutDataMapRequest.create方法的具体用法?Java PutDataMapRequest.create怎么用?Java PutDataMapRequest.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.gms.wearable.PutDataMapRequest
的用法示例。
在下文中一共展示了PutDataMapRequest.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onConfigurationAddedOrEdited
import com.google.android.gms.wearable.PutDataMapRequest; //导入方法依赖的package包/类
/**
* 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 (mGoogleApiClient == null || !mGoogleApiClient.isConnected())
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(mGoogleApiClient, request);
}
示例2: sendTrackingStatusDataMap
import com.google.android.gms.wearable.PutDataMapRequest; //导入方法依赖的package包/类
/**
* 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");
}
});
}
示例3: sendAcceleroMessage
import com.google.android.gms.wearable.PutDataMapRequest; //导入方法依赖的package包/类
public static PendingResult<DataApi.DataItemResult> sendAcceleroMessage(AccelerometerData accelerometerData, GoogleApiClient googleApiClient) {
PutDataMapRequest dataMapRequest = PutDataMapRequest.create(ACC_PATH);
acceleroMessageUri = dataMapRequest.getUri();
DataMap dataMap = dataMapRequest.getDataMap();
//Data set
dataMap.putFloatArray(VALUE_STR, new float[]{accelerometerData.getAccX(), accelerometerData.getAccY(), accelerometerData.getAccZ()});
// Data Push
PutDataRequest request = dataMapRequest.asPutDataRequest();
PendingResult<DataApi.DataItemResult> pendingResult = Wearable.DataApi.putDataItem(googleApiClient, request);
return pendingResult;
}
示例4: stopLogger
import com.google.android.gms.wearable.PutDataMapRequest; //导入方法依赖的package包/类
private void stopLogger() {
File dir = getFilesDir();
File[] subFiles = dir.listFiles();
if (subFiles != null) {
for (File file : subFiles) {
if (file.getName().contains(recentIgcFileName)) {
if (debugMode) Log.d(TAG, "Now checking File " + file.getName());
Asset asset = createAssetFromTextfile(file);
PutDataMapRequest dataMap = PutDataMapRequest.create(Statics.DATAIGC + file.getName());
dataMap.getDataMap().putString("igcname", file.getName());
dataMap.getDataMap().putAsset("igcfile", asset);
PutDataRequest request = dataMap.asPutDataRequest();
request.setUrgent();
Wearable.DataApi.putDataItem(mGoogleApiClient, request);
}
}
}
loggerRunning = false;
loggerState.setText("");
}
示例5: sendTreatment
import com.google.android.gms.wearable.PutDataMapRequest; //导入方法依赖的package包/类
public static void sendTreatment(double carbs, double insulin, double bloodtest, 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().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!");
}
}
示例6: sendDataReceived
import com.google.android.gms.wearable.PutDataMapRequest; //导入方法依赖的package包/类
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!");
}
}
示例7: doInBackground
import com.google.android.gms.wearable.PutDataMapRequest; //导入方法依赖的package包/类
@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;
}
示例8: update
import com.google.android.gms.wearable.PutDataMapRequest; //导入方法依赖的package包/类
/**
* This method is called when someone wants to update something
* in our content provider.
*/
@Override
public int update(Uri uri, ContentValues values, String ignored1,
String[] ignored2) {
// you can't change a task id
if( values.containsKey(COLUMN_TASKID))
throw new UnsupportedOperationException();
long id = ContentUris.parseId(uri);
int count = db.update(DATABASE_TABLE, values,
COLUMN_TASKID + "=?",
new String[]{Long.toString(id)});
if (count > 0)
getContext().getContentResolver().notifyChange(uri, null);
// Update to google Play for wearable support
PutDataMapRequest dataMap = PutDataMapRequest.create(
PLAY_BASE_URL + "/" + id);
DataMap map = dataMap.getDataMap();
map.putLong(COLUMN_TASKID, values.getAsLong(COLUMN_TASKID));
map.putString(COLUMN_TITLE, values.getAsString(COLUMN_TITLE));
map.putLong(COLUMN_DATE_TIME, values.getAsLong(COLUMN_DATE_TIME));
map.putString(COLUMN_NOTES, values.getAsString(COLUMN_NOTES));
PutDataRequest request = dataMap.asPutDataRequest();
Wearable.DataApi.putDataItem(googleApiClient, request);
return count;
}
示例9: sendState
import com.google.android.gms.wearable.PutDataMapRequest; //导入方法依赖的package包/类
public void sendState(boolean state) {
final PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(Const.LOCK_PATH);
Date d = new Date();
putDataMapRequest.getDataMap().putLong("timestamp", d.getTime());
putDataMapRequest.getDataMap().putBoolean("state", state);
if (!mGoogleApiClient.isConnected())
throw new RuntimeException("Cannot send data item when connection is not ready");
Log.d(Const.TAG_ACTIVITY, "Preparing data item for send, isConnected=" + mGoogleApiClient.isConnected());
final 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(Const.TAG_ACTIVITY, "Failed to send data map item for " + Const.LOCK_PATH + " status: " + dataItemResult.getStatus().getStatusCode());
} else {
Log.d(Const.TAG_ACTIVITY, "Sent data map item for " + Const.LOCK_PATH + " " + putDataMapRequest);
}
}
});
}
示例10: setKeySet
import com.google.android.gms.wearable.PutDataMapRequest; //导入方法依赖的package包/类
private static void setKeySet(GoogleApiClient apiClient, String path, ArrayList<String> keySet) {
final PutDataMapRequest request = PutDataMapRequest.create(path);
final DataMap dataMap = request.getDataMap();
dataMap.putStringArrayList(KEY_KEY_SET, keySet);
Wearable.DataApi.putDataItem(apiClient, request.asPutDataRequest()).await();
}
示例11: sendTelegramToWear
import com.google.android.gms.wearable.PutDataMapRequest; //导入方法依赖的package包/类
private void sendTelegramToWear(StateTelegram telegram) {
Log.d("ApiServiceWidget", "Sending data to wear");
if(mGoogleApiClient != null
&& mGoogleApiClient.isConnected()) {
Log.d("ApiServiceWidget", "Wear connected....");
//just to be sure not to use more power than needed
if (telegram.equals(mLastSentTelegram)) {
Log.d("ApiServiceWidget", "Skipping Wear update as the data didn't change");
return;
}
PutDataMapRequest mapRequest = PutDataMapRequest.create(DataInterface.PATH_NOTIFICATION);
DataProtocol.addTelegramToData(telegram, mapRequest.getDataMap());
PutDataRequest request = mapRequest.asPutDataRequest();
Log.d("ApiServiceWidget", "Posting data");
Wearable.DataApi.putDataItem(mGoogleApiClient, request);
mLastSentTelegram = telegram;
}
}
示例12: putConfigDataItem
import com.google.android.gms.wearable.PutDataMapRequest; //导入方法依赖的package包/类
/**
* 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) {
PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(PATH_WITH_FEATURE);
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) {
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "putDataItem result status: " + dataItemResult.getStatus());
}
}
});
}
示例13: handleSensors
import com.google.android.gms.wearable.PutDataMapRequest; //导入方法依赖的package包/类
private void handleSensors(final String path, final int sensorID, final int acuracy) {
if(validateConnection()) {
PutDataMapRequest dataMap = PutDataMapRequest.create(path);
dataMap.getDataMap().putInt(SensorConstants.SENSOR_ID, sensorID);
dataMap.getDataMap().putInt(SensorConstants.ACCURACY, acuracy);
dataMap.getDataMap().putLong("Time",System.currentTimeMillis());
PutDataRequest putDataRequest = dataMap.asPutDataRequest();
putDataRequest = putDataRequest.setUrgent();
Wearable.DataApi.putDataItem(googleApiClient, putDataRequest).setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
@Override
public void onResult(DataApi.DataItemResult dataItemResult) {
Log.d(TAG, "Sending new sensor ++++++++" + path +" " + sensorID + ": " + dataItemResult.getStatus().isSuccess());
}
});
}
}
示例14: buildDataRequest
import com.google.android.gms.wearable.PutDataMapRequest; //导入方法依赖的package包/类
/**
* Builds a {@link com.google.android.gms.wearable.PutDataRequest} which holds a JSON
* representation of the feedback collected.
*/
private PutDataRequest buildDataRequest() throws JSONException {
PutDataMapRequest putDataMapRequest = PutDataMapRequest
.create(HomeListenerService.PATH_RESPONSE);
DataMap dataMap = putDataMapRequest.getDataMap();
JSONArray jsonArray = new JSONArray();
if (!responses.isEmpty()) {
JSONObject sessionObj = new JSONObject();
sessionObj.put("s", mSessionId);
jsonArray.put(0, sessionObj);
int i = 1;
for (Integer key : responses.keySet()) {
JSONObject obj = new JSONObject();
obj.put("q", key);
obj.put("a", responses.get(key));
jsonArray.put(i++, obj);
}
}
String response = jsonArray.toString();
LOGD(TAG, "JSON representation of the response: " + response);
dataMap.putString("response", response);
return putDataMapRequest.asPutDataRequest();
}
示例15: sendWeatherDataToWatch
import com.google.android.gms.wearable.PutDataMapRequest; //导入方法依赖的package包/类
private void sendWeatherDataToWatch() {
PutDataMapRequest putDataMapRequest = PutDataMapRequest.create("/weather");
if (hightempforwatch != 0) {
putDataMapRequest.getDataMap().putInt("highTemp", hightempforwatch);
Log.d("Test","High Temp :"+String.valueOf(putDataMapRequest.getDataMap().getInt("highTemp")));
}
if (lowtempforWatch != 0) {
putDataMapRequest.getDataMap().putInt("lowTemp", lowtempforWatch);
Log.d("Test","Low Temp :"+ String.valueOf(putDataMapRequest.getDataMap().getInt("lowTemp")));
}
if (weatherIdforWatch != 0) {
putDataMapRequest.getDataMap().putInt("weatherId", weatherIdforWatch);
Log.d("Test", "Weather ID: "+String.valueOf(putDataMapRequest.getDataMap().getInt("weatherId")));
}
putDataMapRequest.setUrgent();
PutDataRequest putDataRequest = putDataMapRequest.asPutDataRequest();
Wearable.DataApi.putDataItem(MainActivity.googleApiClient, putDataRequest)
.setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
@Override
public void onResult(DataApi.DataItemResult result) {
if (!result.getStatus().isSuccess()) {
System.out.println("Failure with code: " + result.getStatus().getStatusCode());
} else {
System.out.println("Success: " + result.getDataItem().getUri());
}
}
});
}