本文整理汇总了Java中com.google.android.gms.wearable.MessageEvent.getData方法的典型用法代码示例。如果您正苦于以下问题:Java MessageEvent.getData方法的具体用法?Java MessageEvent.getData怎么用?Java MessageEvent.getData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.gms.wearable.MessageEvent
的用法示例。
在下文中一共展示了MessageEvent.getData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onMessageReceived
import com.google.android.gms.wearable.MessageEvent; //导入方法依赖的package包/类
@Override
public void onMessageReceived(MessageEvent messageEvent) {
if (messageEvent.getPath().equals("/heartRate")) {
final String message = new String(messageEvent.getData());
Log.v("pactchat", "Message path received on watch is: " + messageEvent.getPath());
Log.v("packtchat", "Message received on watch is: " + message);
// Broadcast message to wearable activity for display
Intent messageIntent = new Intent();
messageIntent.setAction(Intent.ACTION_SEND);
messageIntent.putExtra("heart", message);
LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent);
}
else {
super.onMessageReceived(messageEvent);
}
}
示例2: onMessageReceived
import com.google.android.gms.wearable.MessageEvent; //导入方法依赖的package包/类
@Override
public void onMessageReceived(MessageEvent messageEvent) {
if (messageEvent.getPath().equals("/stepcount")) {
final String message = new String(messageEvent.getData());
Log.v("pactchat", "Message path received on watch is: " + messageEvent.getPath());
Log.v("packtchat", "Message received on watch is: " + message);
// Broadcast message to wearable activity for display
Intent messageIntent = new Intent();
messageIntent.setAction(Intent.ACTION_SEND);
messageIntent.putExtra("message", message);
LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent);
}
else {
super.onMessageReceived(messageEvent);
}
}
示例3: onMessageReceived
import com.google.android.gms.wearable.MessageEvent; //导入方法依赖的package包/类
@Override
public void onMessageReceived(MessageEvent messageEvent) {
if (messageEvent.getPath().equals("/message_path")) {
final String message = new String(messageEvent.getData());
Log.v("myTag", "Message path received on watch is: " + messageEvent.getPath());
Log.v("myTag", "Message received on watch is: " + message);
// Broadcast message to wearable activity for display
Intent messageIntent = new Intent();
messageIntent.setAction(Intent.ACTION_SEND);
messageIntent.putExtra("message", message);
LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent);
}
else {
super.onMessageReceived(messageEvent);
}
}
示例4: onMessageReceived
import com.google.android.gms.wearable.MessageEvent; //导入方法依赖的package包/类
@Override
public void onMessageReceived(MessageEvent messageEvent) {
if (messageEvent.getPath().equals("/from-wear")) {
final String message = new String(messageEvent.getData());
Log.v("pactchat", "Message path received on watch is: " + messageEvent.getPath());
Log.v("packtchat", "Message received on watch is: " + message);
// Broadcast message to wearable activity for display
Intent messageIntent = new Intent();
messageIntent.setAction(Intent.ACTION_SEND);
messageIntent.putExtra("message", message);
LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent);
}
else {
super.onMessageReceived(messageEvent);
}
}
示例5: onMessageReceived
import com.google.android.gms.wearable.MessageEvent; //导入方法依赖的package包/类
@Override
public void onMessageReceived(MessageEvent messageEvent) {
if (messageEvent.getPath().equals("/stepcount")) {
final String message = new String(messageEvent.getData());
Log.v(TAG, "Message path received from wear is: " + messageEvent.getPath());
Log.v(TAG, "Message received on watch is: " + message);
// Broadcast message to wearable activity for display
Intent messageIntent = new Intent();
messageIntent.setAction(Intent.ACTION_SEND);
messageIntent.putExtra("message", message);
LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent);
}
else {
super.onMessageReceived(messageEvent);
}
}
示例6: onMessageReceived
import com.google.android.gms.wearable.MessageEvent; //导入方法依赖的package包/类
@Override
public void onMessageReceived(MessageEvent messageEvent) {
//This method will call while any message is posted by the watch to the phone.
//This is message api, so if the phone is not connected message will be lost.
//No guarantee of the message delivery
//check path of the message
if (messageEvent.getPath().equalsIgnoreCase(STEP_COUNT_MESSAGES_PATH)) {
//Extract the values
String stepCount = new String(messageEvent.getData());
Log.d("Step count: ", stepCount + " ");
//send broadcast to update the UI in MainActivity based on the tracking status
Intent intent = new Intent(TRACKING_COUNT_ACTION);
intent.putExtra("step-count", stepCount);
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
} else {
super.onMessageReceived(messageEvent);
}
}
示例7: onMessageReceived
import com.google.android.gms.wearable.MessageEvent; //导入方法依赖的package包/类
@Override
public void onMessageReceived(MessageEvent messageEvent) {
String message = new String(messageEvent.getData());
if (messageEvent.getPath().equals(Constants.MYCROFT_QUERY_MESSAGE_PATH)) {
Log.d(TAG, "MycroftWearRequest Message: " + message);
Intent startIntent = new Intent(this, MainActivity.class);
startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startIntent.putExtra("MYCROFT_WEAR_REQUEST", message);
startActivity(startIntent);
handoffWearRequest(message);
}
}
示例8: onMessageReceived
import com.google.android.gms.wearable.MessageEvent; //导入方法依赖的package包/类
@Override
public void onMessageReceived(MessageEvent messageEvent) {
super.onMessageReceived(messageEvent);
if (messageEvent.getPath().equals("/BatteryLevel")) {
String s = new String(messageEvent.getData());
Log.d(this.getClass().getSimpleName(), "受信したバッテリーレベル = " + s);
MyWearApplication app = (MyWearApplication) getApplication();
try {
app.setBatteryLevel(Integer.parseInt(s));
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
}
示例9: onMessageReceived
import com.google.android.gms.wearable.MessageEvent; //导入方法依赖的package包/类
@Override
public void onMessageReceived(final MessageEvent messageEvent) {
super.onMessageReceived(messageEvent);
switch (messageEvent.getPath()) {
case DataPaths.Messages.SEARCH_RESULT:
WearSearchData.Results searchResults = null;
final byte[] data = messageEvent.getData();
if (data != null && data.length != 0) {
try {
searchResults = WearSearchData.Results.parseFrom(data);
} catch (InvalidProtocolBufferNanoException e) {
Log.w(TAG, e);
}
}
if (searchResults == null) {
searchResults = new WearSearchData.Results();
}
EventBus.getDefault().post(new EventSearchResults(searchResults));
break;
}
}
示例10: startVibration
import com.google.android.gms.wearable.MessageEvent; //导入方法依赖的package包/类
/**
* バイブレーションを開始する.
* @param messageEvent メッセージ
*/
private void startVibration(final MessageEvent messageEvent) {
// get vibration pattern
String mPattern = new String(messageEvent.getData());
// Make array of pattern
String[] mPatternArray = mPattern.split(",", 0);
long[] mPatternLong = new long[mPatternArray.length + 1];
mPatternLong[0] = 0;
for (int i = 1; i < mPatternLong.length; i++) {
mPatternLong[i] = Integer.parseInt(mPatternArray[i - 1]);
}
Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
vibrator.vibrate(mPatternLong, -1);
}
示例11: onMessageReceived
import com.google.android.gms.wearable.MessageEvent; //导入方法依赖的package包/类
@Override
public void onMessageReceived(MessageEvent messageEvent) {
final String message = new String(messageEvent.getData());
Log.v("myTag", "Message path received on watch is: " + messageEvent.getPath());
Log.v("myTag", "Message received on watch is: " + message);
Intent messageIntent = new Intent();
messageIntent.setAction(Intent.ACTION_SEND);
messageIntent.putExtra("path", messageEvent.getPath());
messageIntent.putExtra("message", new String(messageEvent.getData()));
LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent);
super.onMessageReceived(messageEvent);
}
示例12: onMessageReceived
import com.google.android.gms.wearable.MessageEvent; //导入方法依赖的package包/类
@Override
public void onMessageReceived(MessageEvent messageEvent) {
if (messageEvent.getPath().equals("/MainActivity")) {
final String message = new String(messageEvent.getData());
Log.i(TAG, "Message path received on watch is: " + messageEvent.getPath());
Log.i(TAG, "Message received on watch is: " + message);
Intent messageIntent = new Intent();
messageIntent.setAction(Intent.ACTION_SEND);
messageIntent.putExtra("message", message);
LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent);
}
else {
super.onMessageReceived(messageEvent);
}
}
示例13: onMessageReceived
import com.google.android.gms.wearable.MessageEvent; //导入方法依赖的package包/类
/**
* This method is called when a message from a wearable device is received
*
* @param messageEvent
*/
@Override
public void onMessageReceived(MessageEvent messageEvent) {
LogHandler.configureLogger();
if (messageEvent.getPath().equals(WearableConstants.RECEIVER_ACTION_TRIGGER_PATH)) {
String messageData = new String(messageEvent.getData());
Log.d("Wear_ListenerService", "Message received: " + messageData);
// trigger api intent
parseMessage(messageData);
} else if (messageEvent.getPath().equals(WearableConstants.REQUEST_DATA_UPDATE_PATH)) {
UtilityService.forceWearDataUpdate(this);
} else if (messageEvent.getPath().equals(WearableConstants.REQUEST_SETTINGS_UPDATE_PATH)) {
UtilityService.forceWearSettingsUpdate(this);
}
}
示例14: onMessageReceived
import com.google.android.gms.wearable.MessageEvent; //导入方法依赖的package包/类
@Override
public void onMessageReceived(MessageEvent messageEvent) {
if (messageEvent.getPath().equals("/heart")) {
final String message = new String(messageEvent.getData());
Log.v("myTag", "Message path received on watch is: " + messageEvent.getPath());
Log.v("myTag", "Message received on watch is: " + message);
// Broadcast message to wearable activity for display
Intent messageIntent = new Intent();
messageIntent.setAction(Intent.ACTION_SEND);
messageIntent.putExtra("message", message);
LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent);
Intent intent2 = new Intent(getApplicationContext(), MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent2,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(getApplicationContext())
.setAutoCancel(true) //Automatically delete the notification
.setSmallIcon(R.drawable.ic_heart_icon) //Notification icon
.setContentIntent(pendingIntent)
.setContentTitle("Open upbeat")
.setContentText("UpBeat to check the pulse")
.setCategory(Notification.CATEGORY_REMINDER)
.setPriority(Notification.PRIORITY_HIGH)
.setSound(defaultSoundUri);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getApplicationContext());
notificationManager.notify(0, notificationBuilder.build());
}
else {
super.onMessageReceived(messageEvent);
}
}
示例15: onMessageReceived
import com.google.android.gms.wearable.MessageEvent; //导入方法依赖的package包/类
@Override
public void onMessageReceived(final MessageEvent messageEvent) {
final String message = new String(messageEvent.getData());
switch (messageEvent.getPath()) {
case Constants.UART.DEVICE_CONNECTED: {
// Disconnect action
final Intent disconnectIntent = new Intent(ActionReceiver.ACTION_DISCONNECT);
disconnectIntent.putExtra(ActionReceiver.EXTRA_DATA, Constants.UART.PROFILE);
final PendingIntent disconnectAction = PendingIntent.getBroadcast(this, UART_DISCONNECT, disconnectIntent, PendingIntent.FLAG_CANCEL_CURRENT);
// Open action
final Intent intent = new Intent(this, UARTConfigurationsActivity.class);
final PendingIntent pendingIntent = PendingIntent.getActivity(this, UART_SHOW_CONFIGURATIONS, intent, PendingIntent.FLAG_UPDATE_CURRENT);
final NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setContentIntent(pendingIntent)
.setOngoing(true)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(getString(R.string.notif_uart_device_connected))
.setContentText(message)
.addAction(new NotificationCompat.Action(R.drawable.ic_full_bluetooth, getString(R.string.action_disconnect), disconnectAction))
.setLocalOnly(true);
NotificationManagerCompat.from(this).notify(UART_NOTIFICATION_ID, builder.build());
break;
}
case Constants.UART.DEVICE_LINKLOSS:
case Constants.UART.DEVICE_DISCONNECTED: {
NotificationManagerCompat.from(this).cancel(UART_NOTIFICATION_ID);
}
default:
super.onMessageReceived(messageEvent);
break;
}
}