Course Content

Course Content

Sensors in Android

Sensors in Android


In today's video our topic is Sensors in Android.

Do we even know that in our mobile phone how many type of Sensors are there and which particular operations do they perform, and how our phone deals with them.?

Sensor by its name suggests that it means in which sense we use our phone. They are used to make the work of user is easy.

Sensors can be used to monitor the three dimensional device movement or change in the environment of the device.

There are different types of Sensors in Android. In today's era 80% off mobile market is captured by Android.

The first type of Sensor which we will talk about is Motion Sensors. This sensor is used to recognized the distance of mobile phone user to its mobile phone when not physically used. If you take example, we have noticed that when we are talking on call with someone the screen of mobile phone goes on and off.

The second type of sensor is Position sensor. This sensor is used to find the position of our mobile phone in numerical value with reference to x axis, y axis and z axis.

The third type of sensor is Environmental sensor. It is used to measure the climatic condition, weather condition, and temperature of our mobile phone.

In Motion sensors, Rotation and Acceleration sensors will be used. While in Position sensor Orientation and Location sensors will be used. And in the Environmental sensor, different sensors like Ambient temperature, Barometric pressure, Light intensity, and humidity is used.

Android sensor API provides many classes and interfaces. The important classes and interfaces of sensor API are,

SensorManager class

Sensor class

SensorEvent class

SensorEventListener Interface

In SensorManager class, it lets us access the devices sensor and create an instance of the sensor service. It provides various methods for accessing and listing sensors, registering and unregistering sensors.

We can get the instance of SensorManager by calling the method getSystemService() and passing the SENSOR_SERVICE constant in it.

Example :


In Sensor class, the android.hardware.sensor provides methods to get information of the sensors such as sensor name, sensor type, sensor resolution etc...

Identification Methods of Sensor class are, getName(), getType(), getVendor(), and getVersion().

In SensorEvent class, its instance is created by the system. It provides information about the sensor. If we are creating particular instance of sensor class then we can find the value, accuracy, and timestamp of that sensor.

In SensorEventListener Interface, it provides two call back methods to get information when sensor values (x,y,z) change or sensor accuracy changes.

"void onAccuracyChanged(Sensor sensor, int accuracy)" it is called when sensor accuracy is changed.

"void onSensorChanged(SensorEvent event) it is called when sensor values are changed"


Recommended Courses

Share With Friend

Have a friend to whom you would want to share this course?

Download LearnVern App

App Preview Image
App QR Code Image
Code Scan or Download the app
Google Play Store
App Store
397K+ Downloads
App Download Section Circle 1
4.57 Avg. Ratings
App Download Section Circle 2
13K+ Reviews
App Download Section Circle 3
  • Learn anywhere on the go
  • Get regular updates about your enrolled or new courses
  • Share content with your friends
  • Evaluate your progress through practice tests
  • No internet connection needed
  • Enroll for the webinar and join at the time of the webinar from anywhere