SlideShare a Scribd company logo
Android	
  Sensors	
  
Jussi	
  Pohjolainen	
  
Overview	
  
•  SensorManager:	
  Access	
  to	
  sensors	
  if	
  
hardware	
  supports	
  
•  SensorEventListener:	
  Interface	
  for	
  class	
  to	
  
listen	
  sensor	
  values	
  as	
  they	
  change	
  in	
  =me	
  
SensorManager
•  Access	
  to	
  device’s	
  sensors	
  
•  Reference	
  by	
  calling	
  getSystemService
•  Disable	
  sensors	
  if	
  you	
  don’t	
  need	
  them!	
  (drain	
  
baEery)	
  
	
  
Sensor	
  Type	
  
•  Accelerometer,	
  Orienta=on	
  
•  Light	
  
•  Magne=c	
  field	
  
•  Proximity	
  
•  Temperature	
  
•  …	
  
	
  
Sampling	
  Rate	
  
•  How	
  fast	
  try	
  to	
  get	
  the	
  sensor	
  data	
  
•  Reques=ng	
  specific	
  sampling	
  rate..	
  Hint	
  to	
  the	
  
system,	
  no	
  guarantees	
  
•  SensorManager	
  holds	
  constant	
  variables:	
  
– Fastest	
  
– Game	
  
– Normal	
  
– User	
  Interface	
  
	
  
Accuracy	
  
•  How	
  accurate	
  is	
  the	
  informa=on?	
  
– High	
  
– Low	
  
– Medium	
  
– Unreliable	
  
•  This	
  is	
  informa=on	
  is	
  sent	
  to	
  listener	
  
SensorManager	
  Example	
  
public class SensorActivity extends Activity implements SensorEventListener {
private SensorManager mSensorManager;
private Sensor mAccelerometer;
public SensorActivity() {
mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)
}
protected void onResume() {
super.onResume();
mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL);
}
protected void onPause() {
super.onPause();
mSensorManager.unregisteredListener(this);
}
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
public void onSensorChanged(SensorEvent event) {
}
}
Sensor	
  Simulator	
  
•  The	
  current	
  Android	
  emulator	
  does	
  not	
  
support	
  sensors	
  
•  Use	
  Sensor	
  Simulator,	
  open	
  source	
  project	
  
developed	
  by	
  Open	
  Intents	
  
•  Supports	
  accelerometer,	
  compass,	
  
orienta=on,	
  and	
  temperature	
  sensors,	
  
•  Download	
  it	
  from: 	
  	
  
– hEp://code.google.com/p/openintents/wiki/
SensorSimulator	
  
Instruc=ons	
  
1.  Download	
  the	
  latest	
  sensorsimulator-
x.x.x.zip from	
  the	
  download	
  tab	
  and	
  unzip.	
  
2.  Start	
  bin/sensorsimulator-x.x.x.jar (Java	
  
standalone	
  applica=on).	
  
1.  java –jar sensorsimulator-x.x.x.jar
3.  Install	
  bin/SensorSimulatorSettings-
x.x.x.apk on	
  your	
  Android	
  emulator.	
  
4.  Launch	
  SensorSimulator	
  on	
  the	
  emulator.	
  
5.  Enter	
  IP	
  address	
  and	
  socket	
  (port)	
  number	
  into	
  
the	
  emulator	
  
2.	
  Start	
  the	
  Sensor	
  Simulator	
  Jar	
  
3.	
  Install	
  Sensor	
  Simulator	
  Apk	
  
4.	
  Launch	
  Sensor	
  Simulator	
  in	
  
Emulator	
  
5.	
  Configure	
  App	
  
6.	
  Enable	
  Connec=on	
  
Android Sensors
Using	
  Sensor	
  Simulator	
  in	
  Your	
  App	
  
•  Add	
  external	
  JAR	
  lib/sensorsimulator-
lib.x.x.x.jar	
  to	
  your	
  project	
  
•  Use	
  sensorsimulator	
  classes	
  
•  Get	
  reference	
  to	
  SensorManagerSimulator	
  
instead	
  of	
  SensorManager	
  
•  Connect	
  to	
  simulator	
  
•  Add	
  permission	
  to	
  use	
  internet	
  
Add	
  .jar	
  to	
  Project	
  
Android Sensors
Android Sensors
Android Sensors

More Related Content

PDF
Sensors on android
PDF
Sensors and location based services
ODP
Android sensors
PPSX
Sensor's inside
PPTX
Android Sensor
PPTX
Android Training (Sensors)
PPT
Smartphone sensor and gesture
PPT
Android Sensor System
Sensors on android
Sensors and location based services
Android sensors
Sensor's inside
Android Sensor
Android Training (Sensors)
Smartphone sensor and gesture
Android Sensor System

What's hot (20)

PPTX
Android Sensor and Framework - AWARE
PDF
Generic sensors for the Web
PPTX
Mobile Sensors
PPTX
Peno sensor
PPT
Fire fighting robot using 8051 microcontroller
PPTX
Design of Arduino based fire fighting Robot
PPTX
Human presence detection based room light controller using pir2.pptx [repaired]
PPTX
Mebin progress
PPTX
Sensors and its type by ss
PPTX
Tk2323 lecture 10 sensor
PPTX
Fire Fighting Robot
PPTX
fire fighting robot
PDF
IRJET- Fire Fighting Robot using Arduino
PPTX
Sensors by khaleel
PDF
IRJET-Android Controlled Firefighting Robot using Arduino
PPTX
Automatic fire fighting robot
PPT
Fire Fighting Robot by saurabh
PPTX
Fire fighting robot
PPTX
Fire fighting robot ppt
PPTX
Automatic Fire Fighting Robot by St John College
Android Sensor and Framework - AWARE
Generic sensors for the Web
Mobile Sensors
Peno sensor
Fire fighting robot using 8051 microcontroller
Design of Arduino based fire fighting Robot
Human presence detection based room light controller using pir2.pptx [repaired]
Mebin progress
Sensors and its type by ss
Tk2323 lecture 10 sensor
Fire Fighting Robot
fire fighting robot
IRJET- Fire Fighting Robot using Arduino
Sensors by khaleel
IRJET-Android Controlled Firefighting Robot using Arduino
Automatic fire fighting robot
Fire Fighting Robot by saurabh
Fire fighting robot
Fire fighting robot ppt
Automatic Fire Fighting Robot by St John College
Ad

Viewers also liked (20)

PPTX
Game controlling via android
PDF
Smart Phone CPU
PDF
Android internals 00 - Introduction (rev_1.1)
PDF
Android internals 08 - System start up, Media subsystem (rev_1.1)
PPTX
Samsung processors: Exynos family
PDF
Android internals 01 - Basic concepts of mobile platforms (rev_1.1)
PDF
Android internals 02 - High-level architecture, version control system (rev_1.1)
PDF
Android internals 04 - “Androdized” kernel, Bionic, Logging subsystem (rev_1.1)
PDF
Android internals 06 - Binder, Typical subsystem (rev_1.1)
PDF
Android Security, Signing and Publishing
PDF
Android Http Connection and SAX Parsing
PPTX
Qt Translations
PDF
Responsive Web Site Design
PDF
C# for Java Developers
PDF
Quick Intro to Android Development
PDF
Building Web Services
PDF
Android Essential Tools
PDF
Android internals 03 - Build system, emulator (rev_1.1)
PDF
Review Multicore processing based on ARM architecture
PDF
Android Wi-Fi Manager and Bluetooth Connection
Game controlling via android
Smart Phone CPU
Android internals 00 - Introduction (rev_1.1)
Android internals 08 - System start up, Media subsystem (rev_1.1)
Samsung processors: Exynos family
Android internals 01 - Basic concepts of mobile platforms (rev_1.1)
Android internals 02 - High-level architecture, version control system (rev_1.1)
Android internals 04 - “Androdized” kernel, Bionic, Logging subsystem (rev_1.1)
Android internals 06 - Binder, Typical subsystem (rev_1.1)
Android Security, Signing and Publishing
Android Http Connection and SAX Parsing
Qt Translations
Responsive Web Site Design
C# for Java Developers
Quick Intro to Android Development
Building Web Services
Android Essential Tools
Android internals 03 - Build system, emulator (rev_1.1)
Review Multicore processing based on ARM architecture
Android Wi-Fi Manager and Bluetooth Connection
Ad

Similar to Android Sensors (20)

PPTX
Sensors 9
PPTX
Android Lab Test : Using the sensor gyroscope (english)
PDF
Sensors in Android (old)
PPTX
Android 1.8 sensor
PDF
Week12.pdf
PDF
Android sensor
PPT
Sensing Mobile Devices talk from QCon London 2013
PPTX
Base sensor
PDF
Advanced sensors in Series 40 Java ME apps
PPT
Mobile app development snovasys
PDF
Using sensors in java me apps on series 40
PPTX
Android location and sensors API
DOCX
Android accelerometer sensor tutorial
PPTX
Making sense
DOCX
Sensor android
PDF
Introduction to Android G-sensor
PDF
Jollen's Presentation: Introducing Android low-level
PPT
Easy steps to develop android application (tutorial)
PPT
Android tutorial for beginners-traininginbangalore.com
PDF
From sensor data_to_android_and_back
Sensors 9
Android Lab Test : Using the sensor gyroscope (english)
Sensors in Android (old)
Android 1.8 sensor
Week12.pdf
Android sensor
Sensing Mobile Devices talk from QCon London 2013
Base sensor
Advanced sensors in Series 40 Java ME apps
Mobile app development snovasys
Using sensors in java me apps on series 40
Android location and sensors API
Android accelerometer sensor tutorial
Making sense
Sensor android
Introduction to Android G-sensor
Jollen's Presentation: Introducing Android low-level
Easy steps to develop android application (tutorial)
Android tutorial for beginners-traininginbangalore.com
From sensor data_to_android_and_back

More from Jussi Pohjolainen (20)

PDF
Moved to Speakerdeck
PDF
Java Web Services
PDF
Box2D and libGDX
PDF
libGDX: Screens, Fonts and Preferences
PDF
libGDX: Tiled Maps
PDF
libGDX: User Input and Frame by Frame Animation
PDF
Intro to Building Android Games using libGDX
PDF
Advanced JavaScript Development
PDF
Introduction to JavaScript
PDF
Introduction to AngularJS
PDF
libGDX: Scene2D
PDF
libGDX: Simple Frame Animation
PDF
libGDX: Simple Frame Animation
PDF
libGDX: User Input
PDF
Implementing a Simple Game using libGDX
PDF
Building Android games using LibGDX
PDF
Android Threading
PDF
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
PDF
Creating Games for Asha - platform
PDF
Intro to Asha UI
Moved to Speakerdeck
Java Web Services
Box2D and libGDX
libGDX: Screens, Fonts and Preferences
libGDX: Tiled Maps
libGDX: User Input and Frame by Frame Animation
Intro to Building Android Games using libGDX
Advanced JavaScript Development
Introduction to JavaScript
Introduction to AngularJS
libGDX: Scene2D
libGDX: Simple Frame Animation
libGDX: Simple Frame Animation
libGDX: User Input
Implementing a Simple Game using libGDX
Building Android games using LibGDX
Android Threading
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Games for Asha - platform
Intro to Asha UI

Recently uploaded (20)

PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
KodekX | Application Modernization Development
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
Cloud computing and distributed systems.
PDF
Approach and Philosophy of On baking technology
PPTX
Big Data Technologies - Introduction.pptx
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Chapter 3 Spatial Domain Image Processing.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Network Security Unit 5.pdf for BCA BBA.
KodekX | Application Modernization Development
The AUB Centre for AI in Media Proposal.docx
The Rise and Fall of 3GPP – Time for a Sabbatical?
Encapsulation_ Review paper, used for researhc scholars
Unlocking AI with Model Context Protocol (MCP)
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Review of recent advances in non-invasive hemoglobin estimation
20250228 LYD VKU AI Blended-Learning.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Cloud computing and distributed systems.
Approach and Philosophy of On baking technology
Big Data Technologies - Introduction.pptx
Machine learning based COVID-19 study performance prediction
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy

Android Sensors

  • 1. Android  Sensors   Jussi  Pohjolainen  
  • 2. Overview   •  SensorManager:  Access  to  sensors  if   hardware  supports   •  SensorEventListener:  Interface  for  class  to   listen  sensor  values  as  they  change  in  =me  
  • 3. SensorManager •  Access  to  device’s  sensors   •  Reference  by  calling  getSystemService •  Disable  sensors  if  you  don’t  need  them!  (drain   baEery)    
  • 4. Sensor  Type   •  Accelerometer,  Orienta=on   •  Light   •  Magne=c  field   •  Proximity   •  Temperature   •  …    
  • 5. Sampling  Rate   •  How  fast  try  to  get  the  sensor  data   •  Reques=ng  specific  sampling  rate..  Hint  to  the   system,  no  guarantees   •  SensorManager  holds  constant  variables:   – Fastest   – Game   – Normal   – User  Interface    
  • 6. Accuracy   •  How  accurate  is  the  informa=on?   – High   – Low   – Medium   – Unreliable   •  This  is  informa=on  is  sent  to  listener  
  • 7. SensorManager  Example   public class SensorActivity extends Activity implements SensorEventListener { private SensorManager mSensorManager; private Sensor mAccelerometer; public SensorActivity() { mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) } protected void onResume() { super.onResume(); mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL); } protected void onPause() { super.onPause(); mSensorManager.unregisteredListener(this); } public void onAccuracyChanged(Sensor sensor, int accuracy) { } public void onSensorChanged(SensorEvent event) { } }
  • 8. Sensor  Simulator   •  The  current  Android  emulator  does  not   support  sensors   •  Use  Sensor  Simulator,  open  source  project   developed  by  Open  Intents   •  Supports  accelerometer,  compass,   orienta=on,  and  temperature  sensors,   •  Download  it  from:     – hEp://code.google.com/p/openintents/wiki/ SensorSimulator  
  • 9. Instruc=ons   1.  Download  the  latest  sensorsimulator- x.x.x.zip from  the  download  tab  and  unzip.   2.  Start  bin/sensorsimulator-x.x.x.jar (Java   standalone  applica=on).   1.  java –jar sensorsimulator-x.x.x.jar 3.  Install  bin/SensorSimulatorSettings- x.x.x.apk on  your  Android  emulator.   4.  Launch  SensorSimulator  on  the  emulator.   5.  Enter  IP  address  and  socket  (port)  number  into   the  emulator  
  • 10. 2.  Start  the  Sensor  Simulator  Jar  
  • 11. 3.  Install  Sensor  Simulator  Apk  
  • 12. 4.  Launch  Sensor  Simulator  in   Emulator  
  • 16. Using  Sensor  Simulator  in  Your  App   •  Add  external  JAR  lib/sensorsimulator- lib.x.x.x.jar  to  your  project   •  Use  sensorsimulator  classes   •  Get  reference  to  SensorManagerSimulator   instead  of  SensorManager   •  Connect  to  simulator   •  Add  permission  to  use  internet  
  • 17. Add  .jar  to  Project