本文整理汇总了Java中com.google.android.gms.wearable.PutDataRequest.putAsset方法的典型用法代码示例。如果您正苦于以下问题:Java PutDataRequest.putAsset方法的具体用法?Java PutDataRequest.putAsset怎么用?Java PutDataRequest.putAsset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.gms.wearable.PutDataRequest
的用法示例。
在下文中一共展示了PutDataRequest.putAsset方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: alarmCommand
import com.google.android.gms.wearable.PutDataRequest; //导入方法依赖的package包/类
private void alarmCommand(Intent intent) {
AlarmCommand commandData = intent.getParcelableExtra(KEY_COMMAND_DATA);
LiteAlarmCommand liteAlarmCommand = new LiteAlarmCommand(commandData);
PutDataRequest putDataRequest = PutDataRequest.create(CommPaths.COMMAND_ALARM);
putDataRequest.setData(ParcelPacker.getData(liteAlarmCommand));
if (commandData.getIcon() != null) {
putDataRequest.putAsset(CommPaths.ASSET_ICON, Asset.createFromBytes(commandData.getIcon()));
}
if (commandData.getBackgroundBitmap() != null) {
putDataRequest.putAsset(CommPaths.ASSET_BACKGROUND, Asset.createFromBytes(commandData.getBackgroundBitmap()));
}
putDataRequest.setUrgent();
Wearable.DataApi.putDataItem(googleApiClient, putDataRequest).await();
}
示例2: sendDataItemWithoutConnectionCheck
import com.google.android.gms.wearable.PutDataRequest; //导入方法依赖的package包/类
/**
* Sends payload, should be only called from this class and its subclasses
*
* @param path
* @param data
*/
protected void sendDataItemWithoutConnectionCheck(DataPath path, TimeStampStorable data) {
Logger.logD(getClass().getSimpleName(), "Sending " + path);
PutDataRequest request = PutDataRequest.create(path.getPath());
final byte[] dataToSend = data.getAsBytes();
// check data size whether to send as and asset or plain data item
if (dataToSend.length >= MAX_DATA_ITEM_SIZE_B) {
request.putAsset(DataPath.DEFAULT_ASSET_KEY, Asset.createFromBytes(dataToSend));
} else {
request.setData(dataToSend);
}
if (path.isUrgent()) {
request.setUrgent();
}
PendingResult<DataApi.DataItemResult> pendingResult =
Wearable.DataApi.putDataItem(mGoogleApiClient, request);
}