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.
1 Answer
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
2 Comments
user1602722
thank you for you advice .<br>I will try to use these calss on JNI
DzungPV
You have been wrong, TYPE_AMBIENT_TEMPERATURE not for CPU temperature. It's ambient temperature and have in Galaxy S4 and Moto X