Get data to smartphones from SmartWatch Android Wear

I made some apps (pedometer, heart rate, recorder) for moto360 with android. Everything works, but I don’t know how to save the data on the watch and how to access the smart Data on the phone. I have managed to send a message to the watch, but I cannot send the data from the watch to the phone. I can save the data on the smart phone, but I don’t know how to manage it on the smart watch. Can someone give Do I have a tutorial or an example? thank you very much!

Edit:
The following code is used to track Moto360’s heart rate, and it works fine.
I tried to transfer data from the watch to the phone because I used this tutorial -> https ://developer.android.com/training/wearables/data-layer/data-items.html

After implementing the code from the android page, I cannot run Project on the device!

public class MainActivity extends Activity implements SensorEventListener {


private static final String TAG = "MainActivity";
private TextView mTextViewStepCount;
private TextView mTextViewStepDetect;
private TextView mTextViewHeart;
PutDataMapRequest dataMap = PutDataMapRequest.create("/count");
GoogleApiClient mGoogleApiClient;

@Override
protected void onCreate(Bundle savedInstanceState) {


getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

super.onCreate (savedInstanceState);
setContentView(R.layout.activity_main);

final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);
stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
@Override
public void onLayoutInflated(WatchViewStub stub) {

mTextViewStepCount = (TextView) stub.findViewById(R.id.step_count);
mTextViewStepDetect = (TextView) stub.findViewById(R.id.step_detect );
mTextViewHeart = (TextView) stub.findViewById(R.id.heart);
getStepCount();

}
});
}

private void getStepCount() {
SensorManager mSensorManager = ((SensorManager) getSystemService(SENSOR_SERVICE));
Sensor mHeartRateSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_HEART_RATE);
Sensor mStepCountSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
Sensor mStepDetectSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_DETECTOR);

mSensorManager.registerManager_Nate(Sensor, mSensor, SensorRate) ORMAL);
mSensorManager.registerListener(this, mStepCountSensor, SensorManager.SENSOR_DELAY_NORMAL);
mSensorManager.registerListener(this, mStepDetectSensor, SensorManager.SENSOR_DELAY_NORMAL);
}

private String currentTimeStr() {
Calendar c = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");
return df.format(c.getTime ());
}

public void onAccuracyChanged(Sensor sensor, int accuracy) {
Log.d(TAG, "onAccuracyChanged-accuracy: "+ accuracy);
}

public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_HEART_RATE) {
String msg = "" + ( int) event.values[0];

mTextViewHeart.setText(msg);
Log.d(TAG, msg);

} else if (event .sensor.ge tType() == Sensor.TYPE_STEP_COUNTER) {
String msg = "Count: "+ (int) event.values[0];
mTextViewStepCount.setText(msg);
Log.d (TAG, msg);
} else if (event.sensor.getType() == Sensor.TYPE_STEP_DETECTOR) {
String msg = "Detected at "+ currentTimeStr();
mTextViewStepDetect. setText(msg);
Log.d(TAG, msg);
} else {
Log.d(TAG, "Unknown sensor type");
}
}
}

This code is very helpful to me, I hope it can Help many others 🙂

https://github.com/pocmo/SensorDashboard

I made it for moto360 with android I used some apps (pedometer, heart rate, recorder). Everything is working, but I don’t know how to save the data on the watch and how to access the data on the smartphone. I have managed to send a message to the watch, but I can’t put it in the watch Send the data to the phone. I can save the data on the smart phone, but I don’t know how to manage it on the smart watch. Can someone give me a tutorial or an example? thank you very much!

Edit:
The following code is used to track Moto360’s heart rate, and it works fine.
I tried to transfer data from the watch to the phone because I used this tutorial -> https ://developer.android.com/training/wearables/data-layer/data-items.html

After implementing the code from the android page, I cannot run Project on the device!

public class MainActivity extends Activity implements SensorEventListener {


private static final String TAG = "MainActivity";
private TextView mTextViewStepCount;
private TextView mTextViewStepDetect;
private TextView mTextViewHeart;
PutDataMapRequest dataMap = PutDataMapRequest.create("/count");
GoogleApiClient mGoogleApiClient;

@Override
protected void onCreate(Bundle savedInstanceState) {


getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

super.onCreate (savedInstanceState);
setContentView(R.layout.activity_main);

final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);
stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
@Override
public void onLayoutInflated(WatchViewStub stub) {

mTextViewStepCount = (TextView) stub.findViewById(R.id.step_count);
mTextViewStepDetect = (TextView) stub.findViewById(R.id.step_detect );
mTextViewHeart = (TextView) stub.findViewById(R.id.heart);
getStepCount();

}
});
}

private void getStepCount() {
SensorManager mSensorManager = ((SensorManager) getSystemService(SENSOR_SERVICE));
Sensor mHeartRateSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_HEART_RATE);
Sensor mStepCountSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
Sensor mStepDetectSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_DETECTOR);

mSensorManager.registerManager.Listener(Sensor, mSensor, DETECTOR) MAL);
mSensorManager.registerListener(this, mStepCountSensor, SensorManager.SENSOR_DELAY_NORMAL);
mSensorManager.registerListener(this, mStepDetectSensor, SensorManager.SENSOR_DELAY_NORMAL);
}

private String currentTimeStr() {
Calendar c = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");
return df.format(c.getTime ());
}

public void onAccuracyChanged(Sensor sensor, int accuracy) {
Log.d(TAG, "onAccuracyChanged-accuracy: "+ accuracy);
}

public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_HEART_RATE) {
String msg = "" + ( int) event.values[0];

mTextViewHeart.setText(msg);
Log.d(TAG, msg);

} else if (event .sensor.getT ype() == Sensor.TYPE_STEP_COUNTER) {
String msg = "Count: "+ (int) event.values[0];
mTextViewStepCount.setText(msg);
Log.d (TAG, msg);
} else if (event.sensor.getType() == Sensor.TYPE_STEP_DETECTOR) {
String msg = "Detected at "+ currentTimeStr();
mTextViewStepDetect. setText(msg);
Log.d(TAG, msg);
} else {
Log.d(TAG, "Unknown sensor type");
}
}
}

This code is very helpful to me, I hope it can help many others 🙂

https://github.com/pocmo/SensorDashboard

Leave a Comment

Your email address will not be published.