Home > Net >  Get temperature with smartphone
Get temperature with smartphone

Time:02-10

How can I get the ambient temperature? I have used Sensor.TYPE_AMBIENT_TEMPERATURE but I get that my smartphone does not have this sensor. I have downloaded an app called "Thermometer" from Google play, and the app shows me two temperatures, the external one (obtained from a web page) and the internal one, which I don't know how this app obtains since my smartphone "does not have the sensor ". I have checked my app with the android studio emulator and it seems to work fine. I have downloaded an app to measure the temperature of the battery and the CPU to compare it with that of the "Thermometer" app and they are different by 10oC. I have disconnected from the internet and opened the "thermometer" app and the outside temperature does not appear, since it gets it from the internet, but the inside temperature does appear because it is obtained from a sensor. Does anyone know what sensor this "Thermometer" app can use? Thank you very much for your help.

public Thermometer(Context context) {
        sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
        sensor = sensorManager.getDefaultSensor(Sensor.TYPE_AMBIENT_TEMPERATURE);
    }

    public void start() {

        if (sensor != null) {
            sensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_FASTEST);
        } else {
            Log.e("Mensaje","No Ambient Temperature Sensor !");
        }

    }

    public void stop() {
        sensorManager.unregisterListener(this);
    }


    public void setListener(ThermometerListener l) {
        listener = l;
    }


    @Override
    public void onSensorChanged(SensorEvent sensorEvent) {
        if (sensorEvent.values.length > 0) {
            temperature = sensorEvent.values[0];
            if (listener != null) {
                listener.onNewTemperature(temperature);
            }
        }

    }

CodePudding user response:

  •  Tags:  
  • Related