user1602722
user1602722

Reputation: 121

Get Android's CPU tempareture on NativeActivity

How can I get the CPU tempareture on NativeActivity? I think, I should use jclass and FindClass methods or something similar. I don't know how to do it though.

Upvotes: 1

Views: 368

Answers (1)

Linga
Linga

Reputation: 10545

You can use TYPE_AMBIENT_TEMPERATURE for battery or CPU temperature. TYPE_TEMPERATURE is the depcrecated constant.

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) {
}

Click here to refer

Upvotes: 1

Related Questions