Android	
  Sensors	
  
Jussi	
  Pohjolainen	
  
Overview	
  
•  SensorManager:	
  Access	
  to	
  sensors	
  if	
  
hardware	
  supports	
  
•  SensorEventListener:	
  In...
SensorManager
•  Access	
  to	
  device’s	
  sensors	
  
•  Reference	
  by	
  calling	
  getSystemService
•  Disable	
  s...
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	
...
Accuracy	
  
•  How	
  accurate	
  is	
  the	
  informa=on?	
  
– High	
  
– Low	
  
– Medium	
  
– Unreliable	
  
•  This...
SensorManager	
  Example	
  
public class SensorActivity extends Activity implements SensorEventListener {
private SensorM...
Sensor	
  Simulator	
  
•  The	
  current	
  Android	
  emulator	
  does	
  not	
  
support	
  sensors	
  
•  Use	
  Senso...
Instruc=ons	
  
1.  Download	
  the	
  latest	
  sensorsimulator-
x.x.x.zip from	
  the	
  download	
  tab	
  and	
  unzip...
2.	
  Start	
  the	
  Sensor	
  Simulator	
  Jar	
  
3.	
  Install	
  Sensor	
  Simulator	
  Apk	
  
4.	
  Launch	
  Sensor	
  Simulator	
  in	
  
Emulator	
  
5.	
  Configure	
  App	
  
6.	
  Enable	
  Connec=on	
  
Using	
  Sensor	
  Simulator	
  in	
  Your	
  App	
  
•  Add	
  external	
  JAR	
  lib/sensorsimulator-
lib.x.x.x.jar	
  t...
Add	
  .jar	
  to	
  Project	
  
Android Sensors
Android Sensors
Android Sensors
Android Sensors
Upcoming SlideShare
Loading in...5
×

Android Sensors

2,170

Published on

Published in: Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,170
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Android Sensors

  1. 1. Android  Sensors   Jussi  Pohjolainen  
  2. 2. Overview   •  SensorManager:  Access  to  sensors  if   hardware  supports   •  SensorEventListener:  Interface  for  class  to   listen  sensor  values  as  they  change  in  =me  
  3. 3. SensorManager •  Access  to  device’s  sensors   •  Reference  by  calling  getSystemService •  Disable  sensors  if  you  don’t  need  them!  (drain   baEery)    
  4. 4. Sensor  Type   •  Accelerometer,  Orienta=on   •  Light   •  Magne=c  field   •  Proximity   •  Temperature   •  …    
  5. 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. 6. Accuracy   •  How  accurate  is  the  informa=on?   – High   – Low   – Medium   – Unreliable   •  This  is  informa=on  is  sent  to  listener  
  7. 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. 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. 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. 10. 2.  Start  the  Sensor  Simulator  Jar  
  11. 11. 3.  Install  Sensor  Simulator  Apk  
  12. 12. 4.  Launch  Sensor  Simulator  in   Emulator  
  13. 13. 5.  Configure  App  
  14. 14. 6.  Enable  Connec=on  
  15. 15. 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  
  16. 16. Add  .jar  to  Project  

×