What is Sensor Manager?

Q.7) What is Sensor Manager? Explain the process to manage network cbonnections in Android. [10]

Ans.
Most of the today’s phones are called Smartphones and the only reason behind this is Sensor Manager. Now day’s Android devices have built-in hardware sensors. There are three broad categories of sensors available in Android platform.

1. Motion Sensors
2. Environmental sensors
3. Position sensors

Motion Sensors measure acceleration forces and rotational forces along three axes (x,y,z)

Environmental sensors measure environmental aspects such as temperature and pressure, illumination, and humidity.

Position sensors determine the “physical position” of a device.
Android provides SensorManager and Sensor classes to use the sensors. You can use sensor by instantiate the object of SensorManager class.

SensorManagerMgr = (SensorManager)this.getSystemService(SENSOR_SERVICE);
package com.example.sensormgr;

import java.util.List;

import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;

public class MainActivity extends Activity {
    private SensorManager sMgr;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    TextView sensorsData = (TextView)findViewById(R.id.textView1);

    sMgr = (SensorManager)this.getSystemService(SENSOR_SERVICE);
    List< Sensor> list = sMgr.getSensorList(Sensor.TYPE_ALL);

    StringBuilder data = new StringBuilder();
    for(Sensor sensor: list){
        data.append(sensor.getName() + "\n");
        data.append(sensor.getVendor() + "\n");
        data.append(sensor.getVersion() + "\n");
    }

    sensorsData.setText(data);

        // lv.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, sensor));
    }
}
Post your comment