當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。