我想从设备获取温度。但我不知道我该怎么做。请大家帮我写简单。 谢谢。
I want to get temperature from device. but I don t know how I can do. please help me writing simple. thanks.
您可以使用的 TYPE_AMBIENT_TEMPERATURE 电池或CPU的温度。 TYPE_TEMPERATURE 是depcrecated不变。
You can use TYPE_AMBIENT_TEMPERATURE for battery or CPU temperature. TYPE_TEMPERATURE is the depcrecated constant.
的code,适用修改后的版本在文档应是这样的:
The modified version of code available at documentation should be like this:
public class TempSensorActivity extends Activity, implements SensorEventListener {
private final SensorManager mSensorManager;
private final Sensor mTempSensor;
public TempSensorActivity() {
mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
mTempSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_AMBIENT_TEMPERATURE);
}
protected void onResume() {
super.onResume();
mSensorManager.registerListener(this, mTempSensor, SensorManager.SENSOR_DELAY_NORMAL);
}
protected void onPause() {
super.onPause();
mSensorManager.unregisterListener(this);
}
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
public void onSensorChanged(SensorEvent event) {
}
看更多的传感器文档。
上一篇:而试图购买带有soomla IAP谷歌认证错误错误、soomla、IAP
下一篇:指定的小孩已经有一个父。你必须呼吁孩子的父母第一次removeView()(Android版)你必须、有一个、小孩、父母