本文整理匯總了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);
}