How to use infrared sensor in Android-studio?-ThrowExceptions

Exception or error:

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.

How to solve:

You have to use


. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *