@Override public void onMessageReceived(MessageEvent messageEvent) { if (messageEvent.getPath().equals(PATH_WEATHER_INFO)) { DataMap dataMap = DataMap.fromByteArray(messageEvent.getData()); Bundle bundle = new Bundle(); bundle.putString("minTemp", dataMap.getString("minTemp")); bundle.putString("maxTemp", dataMap.getString("maxTemp")); bundle.putString("weatherId", dataMap.getString("weatherId")); Intent messageIntent = new Intent(); messageIntent.setAction(Intent.ACTION_SEND); messageIntent.putExtras(bundle); LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent); } else { super.onMessageReceived(messageEvent); } }
@Override public void onDataChanged(DataEventBuffer dataEvents) { for (DataEvent event : dataEvents) { if (event.getType() == DataEvent.TYPE_DELETED) { Log.d("TAG", "DataItem deleted: " + event.getDataItem().getUri()); } else if (event.getType() == DataEvent.TYPE_CHANGED) { Log.d("TAG", "DataItem changed: " + event.getDataItem().getUri()); DataMap dataMap = DataMap.fromByteArray(event.getDataItem().getData()); // variable = dataMap.get~("keyname"); で受け取る runOnUiThread( new Runnable() { @Override public void run() { // 受け取り後の処理をここに // resultview.setText(resultstr); } }); } } }