Doubt about how to use a screen to measure temperature by cell phone [closed]

0

I have a question, I have to add a function to measure the temperature of the environment by the smartphone in my android app, but I have no idea how to do this, and I do not know if it has ... Could someone just give me a tip, or tell me if there's no way? kkkk

Thank you.

    
asked by anonymous 18.02.2018 / 15:39

1 answer

1

Your question is very similar to this:

link

and this:

link

You can use TYPE_AMBIENT_TEMPERATURE  to check the temperature of the cpu or battery.

Look at the example given:

import android.app.Activity;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;

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

Take a look here: SensorManager

    
18.02.2018 / 15:53