Wednesday, 27 March 2013


A sensor (also called detector) is a converter that measures a physical quantity and converts
it into a signal which can be read by an observer or by an (today mostly electronic) instrument.

Most Android-powered devices have built-in sensors that measure motion, orientation, and various environmental conditions.

The Android sensor framework lets you access many types of sensors. Some of these sensors are hardware-based and some are software-based. Hardware-based sensors are physical components built into a handset or tablet device.

The Android platform supports three broad categories of sensors:
1.Motion Sensors
2.Environmental Senosors
3.Position Sensors

1.Motion Sensors:
These sensors measure acceleration forces and rotational forces along three axes. This category includes accelerometers, gravity sensors, gyroscopes, and rotational vector sensors.

2.Environmental Sensors:
These sensors measure various environmental parameters, such as ambient air temperature and pressure, illumination, and humidity. This category includes barometers, photometers, and thermometers.

3.Position Sensors:
These sensors measure the physical position of a device. This category includes orientation sensors and magnetometers.

Sensors Android supports several sensors via the SensorManager .

for example have look on following example using SensorManager we can get the list of available sensors from android device.

Getting list of available Sensors:
<RelativeLayout xmlns:android=""
    android:layout_height="match_parent" >

        android:layout_height="wrap_content" >

            android:textAppearance="?android:attr/textAppearanceLarge" />

package com.ram.sensor1;

import java.util.List;

import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends Activity {
SensorManager sensorManager;
TextView display;

protected void onCreate(Bundle savedInstanceState) {

display = (TextView) findViewById(;

sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);

List<Sensor> deviceSensors = sensorManager

StringBuffer sb = new StringBuffer();
sb.append("avialable sensors are :" + "\n" + deviceSensors.size()
+ " sensors found :" + "\n");

for (Sensor sensor : deviceSensors) {
sb.append(sensor.getName() + "\n" + "\n");