Android Sensors

Applications

  • Resizing screen / tilt
  • Environment adjustment of apps, user comfort
  • Adjustment in cinema, prediction of movement
  • Gaming
  • AR
  • AR Gaming
  • AR Navigation
  • Bar codes
  • Geo – tagging, grafitti, recomendations..
  • Network of objects, locations and people, 3D social
  • Giant distributed sensor system
  • Noise mapping
  • And anything you can imagine…

API

  • Package: android.hardware
  • Classes:
    • SensorManager – android service
    • Sensor ,specific sensor
    • SensorEvent – specific event of the sensor = data

API – example setup

public class MainActivity extends Activity implements
SensorEventListener
{
..
private SensorManager sm = null;
...
public void onCreate(Bundle savedInstanceState) {
..
sm = (SensorManager) getSystemService(SENSOR_SERVICE);
}
protected void onResume() {
..
List<Sensor> typedSensors =
sm.getSensorList(Sensor.TYPE_LIGHT);
// also: TYPE_ALL
if (typedSensors == null || typedSensors.size() <= 0) ... error...
sm.registerListener(this, typedSensors.get(0),
SensorManager.SENSOR_DELAY_GAME);
// Rates: SENSOR_DELAY_FASTEST, SENSOR_DELAY_GAME,
//
SENSOR_DELAY_NORMAL, SENSOR_DELAY_UI
}
}

API – example processing event

public class MainActivity extends Activity implements
SensorEventListener
{
..
private float currentValue;
private long lastUpdate;
...
public void onSensorChanged(
SensorEvent event
) {
currentValue = event.values[0];
lastUpdate = event.timestamp;
}
..
}

API – example cleanup

public class MainActivity extends Activity implements
SensorEventListener
{
...
protected void onPause() {
...
sm.unregisterListener(this);
}
...
protected void onStop() {
...
sm.unregisterListener(this);
}
..
}
It's only fair to share...Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInEmail this to someoneBuffer this pageDigg thisFlattr the authorShare on StumbleUponPin on PinterestShare on YummlyShare on VKShare on RedditPrint this pageShare on Tumblr
Related Posts

Add a Comment

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