我想知道是否可以知道磨损装置是否在手边。 我需要运行一个只在手头有脉搏的服务,如果不是,那么就应该停止服务并在手头再次启动它。
答案 0 :(得分:1)
您可以尝试使用心率传感器
public class MainActivity extends WearableActivity implements SensorEventListener {
private static final String TAG = "MainActivity";
private TextView mTextViewHeart;
SensorManager mSensorManager;
Sensor mHeartRateSensor;
SensorEventListener sensorEventListener;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTextViewHeart = (TextView) findViewById(R.id.heart);
mSensorManager = ((SensorManager) getSystemService(SENSOR_SERVICE));
mHeartRateSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_HEART_RATE);
mSensorManager.registerListener(this, mHeartRateSensor, SensorManager.SENSOR_DELAY_NORMAL);
Log.i(TAG, "LISTENER REGISTERED.");
mTextViewHeart.setText("Something here");
mSensorManager.registerListener(sensorEventListener, mHeartRateSensor, mSensorManager.SENSOR_DELAY_FASTEST);
}
public void onResume(){
super.onResume();
}
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
Log.d(TAG, "Unknown sensor type");
}
}
答案 1 :(得分:0)
某些设备(如微软带2)有一个专门用于检测设备是否磨损的传感器。根据项目,您可以考虑为该设备进行开发