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

Asked

Viewed 116 times

0

make me 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, e nem sei se tem como... Could someone just give me a hint, or say if there’s no way? kkkk

Thank you.

1 answer

1

Your doubt is much like this:

https://stackoverflow.com/questions/11931681/how-to-get-device-s-temperature-in-android

and that:

https://stackoverflow.com/questions/6985396/is-there-any-android-api-to-find-sense-room-temperature-programmatically-in-andr

You can use TYPE_AMBIENT_TEMPERATURE to check cpu or battery temperature.

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

  • 1

    Edjane Thank you so much for your help

Browser other questions tagged

You are not signed in. Login or sign up in order to post.