Home > Blog > Android Tech Help – Checking Feasibility before Developing A Sensor-Based Android App

Android Tech Help – Checking Feasibility before Developing A Sensor-Based Android App

29 Jun 2015

Sensors have become an integral part of the Android ecosystem for measuring device orientation, motion, and various environmental conditions. Sensors provide raw data with high precision and accuracy to various location based apps, and are useful in developing three-dimensional device movement or positioning apps. This blog explains how to check sensor on Android devices before developing a sensor-based app.


Sensors in Android Phones

Android-powered devices have various types of sensors depending on the hardware configurations. For example, most handset devices and tablets have an accelerometer and a magnetometer, but fewer devices have barometers or thermometers. Also, some devices can have more than one sensor comprising of two gravity sensors working on different ranges.

The Android mobile operating system has a sensor framework which lets you access many types of sensor functionalities. Some of these sensors are hardware-supported and some are supported by software. Creating a sensor based app which can run efficiently on major Android device is a major challenge faced by developers today.

Request a Free Consultation


Need to ensure the required sensor is supported by the device or not before creating a sensor-based application.


First step is to check for the availability of the sensor on the Android device.
By using SensorManager class, we can know the sensor’s available on an Android device. We need an object of this class to execute the operation with the sample source code below:


SensorManager deviceSensorManager = (SensorManager) getSystemService(SOME_SENSOR_SERVICE);


Using getSensorList() method helps check the presence of sensors like accelerometer, gyroscope, pressure. In the sample code below, if the value returned has size > 0 then it implies that the sensor is present.


A TextView can also be used to test the availability of sensor. Use the sample code below to execute this operation.


List<android.hardware.Sensor> sensorList = deviceSensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER);
if (sensorList.size() > 0) {
sensorPresent = true;
sensor = sensorList.get(0);
sensorPresent = false;
/* Set the face TextView to display sensor presence */
face = (TextView) findViewById(R.id.face);
if (sensorPresent)
face.setText(“Sensor present!”);
face.setText(“Sensor absent.”);

You can also download the executable code for this example: https://docs.google.com/leaf?id=0B_rESQKgad5LZWJhODM4YzktYjc0YS00YmRmLTkzZTYtZDI0ZGRkZDYyNmM3& hl=en_US&authkey=COa-3YoC

Are you currently facing challenges in developing sensor-based mobile applications? And would like to partner with an Android mobile app development company to help you develop a quality Android App for the enterprise?

Get a Free Consultation

Talk to our android experts to help develop a sensor based mobile app today.