androidandroid-sensorsinfrared

How to use infrared sensor in Android-studio?


I have Xiaomi MI smartphone and it has infrared sensor. I am interested, how can I get access to sensor's class and which methods it's class has. I tried to find the information on other resources, but with no results.


Solution

  • You have to use

    SensorManager

    . There is a method called

    getSensorList(int type)

    that you can use to check all the sensors a certain device has. For example you can do similar to the following

      SensorManager mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
      Sensor mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    

    See this for a detailed description of Sensors.