本文整理汇总了Java中com.google.android.gms.wearable.DataMap.fromByteArray方法的典型用法代码示例。如果您正苦于以下问题:Java DataMap.fromByteArray方法的具体用法?Java DataMap.fromByteArray怎么用?Java DataMap.fromByteArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.gms.wearable.DataMap
的用法示例。
在下文中一共展示了DataMap.fromByteArray方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onMessageReceived
import com.google.android.gms.wearable.DataMap; //导入方法依赖的package包/类
@Override // WearableListenerService
public void onMessageReceived(MessageEvent messageEvent) {
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "onMessageReceived: " + messageEvent);
}
if (!messageEvent.getPath().equals(ConfigurationHelper.PATH_WITH_FEATURE)) {
return;
}
byte[] rawData = messageEvent.getData();
// It's allowed that the message carries only some of the keys used in the config DataItem
// and skips the ones that we don't want to change.
DataMap configKeysToOverwrite = DataMap.fromByteArray(rawData);
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "Received watch face config message: " + configKeysToOverwrite);
}
if (googleApiClient == null) {
googleApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(this)
.addOnConnectionFailedListener(this).addApi(Wearable.API).build();
}
if (!googleApiClient.isConnected()) {
ConnectionResult connectionResult =
googleApiClient.blockingConnect(30, TimeUnit.SECONDS);
if (!connectionResult.isSuccess()) {
Log.e(TAG, "Failed to connect to GoogleApiClient.");
return;
}
}
ConfigurationHelper.overwriteKeysInConfigDataMap(googleApiClient, configKeysToOverwrite);
}
示例2: onMessageReceived
import com.google.android.gms.wearable.DataMap; //导入方法依赖的package包/类
@Override // WearableListenerService
public void onMessageReceived(MessageEvent messageEvent) {
if (!messageEvent.getPath().equals(WatchFaceUtil.PATH_WITH_FEATURE)) {
return;
}
byte[] rawData = messageEvent.getData();
// It's allowed that the message carries only some of the keys used in the config DataItem
// and skips the ones that we don't want to change.
DataMap configKeysToOverwrite = DataMap.fromByteArray(rawData);
Log.d(TAG, "Received watch face config message: " + configKeysToOverwrite);
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(this)
.addOnConnectionFailedListener(this).addApi(Wearable.API).build();
}
if (!mGoogleApiClient.isConnected()) {
ConnectionResult connectionResult =
mGoogleApiClient.blockingConnect(30, TimeUnit.SECONDS);
if (!connectionResult.isSuccess()) {
Log.e(TAG, "Failed to connect to GoogleApiClient.");
return;
}
}
WatchFaceUtil.overwriteKeysInConfigDataMap(mGoogleApiClient, configKeysToOverwrite);
}
示例3: decodeAcceleroMessage
import com.google.android.gms.wearable.DataMap; //导入方法依赖的package包/类
public static AccelerometerData decodeAcceleroMessage(DataItem dataItem) {
AccelerometerData accelerometerData = null;
if (MESSAGE_TYPE.ACC.equals(getMessageType(dataItem))) {
DataMap dataMap = DataMap.fromByteArray(dataItem.getData());
float sensordataArray[] = dataMap.getFloatArray(VALUE_STR);
if (sensordataArray != null)
{
accelerometerData = new AccelerometerData(sensordataArray[0], sensordataArray[1], sensordataArray[2]);
}
}
return accelerometerData;
}
示例4: decodeJoystickMessage
import com.google.android.gms.wearable.DataMap; //导入方法依赖的package包/类
public static JoystickData decodeJoystickMessage(DataItem dataItem) {
JoystickData joystickData = null;
if (MESSAGE_TYPE.JOYSTICK.equals(getMessageType(dataItem))) {
DataMap dataMap = DataMap.fromByteArray(dataItem.getData());
float joystickArray[] = dataMap.getFloatArray(VALUE_STR);
if (joystickArray != null)
{
joystickData = new JoystickData(joystickArray[0], joystickArray[1]);
}
}
return joystickData;
}
示例5: decodeInteractionTypeMessage
import com.google.android.gms.wearable.DataMap; //导入方法依赖的package包/类
public static int decodeInteractionTypeMessage(DataItem dataItem) {
int interactionBitfield = InteractionType.NONE;
if (MESSAGE_TYPE.INTERACTION_TYPE.equals(getMessageType(dataItem))) {
DataMap dataMap = DataMap.fromByteArray(dataItem.getData());
interactionBitfield = dataMap.getInt(VALUE_STR);
}
return interactionBitfield;
}
示例6: decodeActionTypeMessage
import com.google.android.gms.wearable.DataMap; //导入方法依赖的package包/类
public static int decodeActionTypeMessage(DataItem dataItem) {
int actionType = -1;
if (MESSAGE_TYPE.ACTION_TYPE.equals(getMessageType(dataItem))) {
DataMap dataMap = DataMap.fromByteArray(dataItem.getData());
actionType = dataMap.getInt(VALUE_STR);
}
return actionType;
}
示例7: onMessageReceived
import com.google.android.gms.wearable.DataMap; //导入方法依赖的package包/类
@Override
public void onMessageReceived(MessageEvent messageEvent) {
Log.d(TAG, "onMessageReceived: " + messageEvent);
switch (messageEvent.getPath()) {
case PATH_DND:
if (messageEvent.getData().length == 0)
return;
int state = (int) messageEvent.getData()[0];
Log.d(TAG, "Target state: " + state);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (state != NotificationManager.INTERRUPTION_FILTER_ALL)
state = NotificationManager.INTERRUPTION_FILTER_ALARMS;
if (state == (int) notificationManager.getCurrentInterruptionFilter())
return;
if (notificationManager.isNotificationPolicyAccessGranted())
notificationManager.setInterruptionFilter(state);
} else if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Intent intent = new Intent(LGHackService.ACTION_SET_STATE);
intent.putExtra(LGHackService.EXTRA_STATE, (int) messageEvent.getData()[0]);
sendBroadcast(intent);
} else {
AudioManager audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
state = state == 4 ? AudioManager.RINGER_MODE_SILENT : AudioManager.RINGER_MODE_NORMAL;
//INTERRUPTION_FILTER_ALARMS
if (state == audioManager.getRingerMode())
return;
audioManager.setRingerMode(state);
}
return;
case PATH_DND_REGISTER:
if (messageEvent.getData().length == 0)
return;
Intent connectIntent = new Intent(WEAR_CALLBACK_CONNECT);
if (messageEvent.getData().length > 1) {
DataMap config = DataMap.fromByteArray(messageEvent.getData());
connectIntent.putExtra("permission", config.getBoolean("permission"));
}
sendBroadcast(connectIntent);
Log.d(TAG, "Connected broadcast");
return;
case PATH_LOGS:
if (messageEvent.getData().length == 0)
return;
Intent logIntent = new Intent(WEAR_CALLBACK_LOGS);
logIntent.putExtra("log", new String(messageEvent.getData()));
sendBroadcast(logIntent);
Log.d(TAG, "Logs broadcast");
return;
}
}