460 likes | 686 Views
Smartphone Sensors and Android Overview. CS/ECE 498 Ashutosh Dhekne (borrowed from Nirupam Roy). Roadmap. An overview of smartphone sensors and possible applications Overview of Android architecture. Smartphone Sensors. Accelerometer Gyroscope Magnetometer Light sensor Humidity sensor
E N D
Smartphone Sensors and Android Overview CS/ECE 498 Ashutosh Dhekne (borrowed from Nirupam Roy)
Roadmap • An overview of smartphone sensors and possible applications • Overview of Android architecture
Smartphone Sensors • Accelerometer • Gyroscope • Magnetometer • Light sensor • Humidity sensor • Touch screen • Barometer • Microphone and Camera …
Smartphone Sensors • Accelerometer • Gyroscope • Magnetometer • Light sensor • Humidity sensor • Touch screen • Barometer • Microphone and Camera …
Android Architecture Your Mobile App
Android Code to Access Sensor Data http://developer.android.com/guide/topics/sensors/sensors_overview.html privateSensorManager sensorManager;...sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);if (sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD) != null){// Success! There's a magnetometer.} else {// Failure! No magnetometer.}
Android Code to Access Sensor Data publicclassSensorActivityextendsActivityimplementsSensorEventListener {privateSensorManagersensorManager;privateSensormLight;@OverridepublicfinalvoidonCreate(BundlesavedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);mLight = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); }@OverridepublicfinalvoidonAccuracyChanged(Sensorsensor, int accuracy) {// Do something here if sensor accuracy changes. }@OverridepublicfinalvoidonSensorChanged(SensorEvent event) {// The light sensor returns a single value.// Many sensors return 3 values, one for each axis.float lux = event.values[0];// Do something with this sensor value. }@OverrideprotectedvoidonResume() {super.onResume();sensorManager.registerListener(this, mLight, SensorManager.SENSOR_DELAY_NORMAL); }@OverrideprotectedvoidonPause() {super.onPause();sensorManager.unregisterListener(this); }} Reading Values How often do you want updates?
Android Code to Access Sensor Data Main Activity XML file Android Manifest file The main computing codes Code for organizing the UI The application meta-data Most of your code will be here Get all needed permissions
Asking for Permissions • Reading or writing might need permissions from the user. <manifest ...><uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE"/> ...</manifest> https://developer.android.com/training/data-storage/files#ExternalStoragePermissions
Become a Developer http://www.imagezap.org/how-to-enable-developer-mode-on-android/