当前位置: 首页>>代码示例>>Java>>正文


Java MessageEvent.getData方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:PacktPublishing,项目名称:Android-Wear-Projects,代码行数:18,代码来源:HeartListener.java

示例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);
    }
}
 
开发者ID:PacktPublishing,项目名称:Android-Wear-Projects,代码行数:18,代码来源:StepListner.java

示例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);
    }
}
 
开发者ID:PacktPublishing,项目名称:Android-Wear-Projects,代码行数:19,代码来源:ListenerService.java

示例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);
    }
}
 
开发者ID:PacktPublishing,项目名称:Android-Wear-Projects,代码行数:18,代码来源:WearListner.java

示例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);
    }
}
 
开发者ID:PacktPublishing,项目名称:Android-Wear-Projects,代码行数:18,代码来源:StepListner.java

示例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);
    }
}
 
开发者ID:kevalpatel2106,项目名称:android-samples,代码行数:22,代码来源:WearService.java

示例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);
    }
}
 
开发者ID:MycroftAI,项目名称:Mycroft-Android,代码行数:17,代码来源:MycroftWearListenerService.java

示例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();
        }
    }
}
 
开发者ID:f97one,项目名称:MirageWatch,代码行数:18,代码来源:HandheldMsgReceiverService.java

示例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;
    }
}
 
开发者ID:Doctoror,项目名称:PainlessMusicPlayer,代码行数:22,代码来源:WearableListenerServiceImpl.java

示例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);
}
 
开发者ID:DeviceConnect,项目名称:DeviceConnect-Android,代码行数:20,代码来源:DataLayerListenerService.java

示例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);

}
 
开发者ID:wlky,项目名称:AnkiDroid-Wear,代码行数:17,代码来源:ListenerService.java

示例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);
    }
}
 
开发者ID:ArturVasilov,项目名称:AndroidCourses,代码行数:17,代码来源:WearableMessageListenerService.java

示例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);
    }
}
 
开发者ID:Power-Switch,项目名称:PowerSwitch_Android,代码行数:23,代码来源:ListenerService.java

示例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);
    }
}
 
开发者ID:PacktPublishing,项目名称:Android-Wear-Projects,代码行数:41,代码来源:MobileListener.java

示例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;
	}
}
 
开发者ID:runtimeco,项目名称:Android-DFU-App,代码行数:36,代码来源:MainWearableListenerService.java


注:本文中的com.google.android.gms.wearable.MessageEvent.getData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。