SlideShare a Scribd company logo
Android application development 
Sensor 
Programming
Android Sensors 
1. Android phones support different sensors. 
2. Today we write test code that reports which sensors our Android device supports. 
3. Unfortunately, the emulator supports none upto SDK 1.5. 
4. But we’ll see how many sensors are supported 
in real device 
5. We’ll create a project named SensorTest for this. 
We’ll test following sensor list: 
1. Accelerometer 
2. Light 
3. Magnetic Field 
4. Orientation 
5. Orientation Raw 
6. Proximity 
7. Temperature 
8. Tricorder This is for SDK 1.5
Let’s create a project named 
SensorTest
Activity to a ListActivity 
1. We change our Activity to a ListActivity
Android Sensors Test 
2. We’ll use SensorManager class 
3. So we declare a List for SensorInfo 
4. SensorInfo is a class defined by us which holds the sensor name and a boolean value 
whether its supported or not. 
5. So we create a SensorInfo class
ListActivity 
6. Let’s get back to our ListActivity 
7. We’ll now populate the list with all sensors and check whether they are enabled
Declare a List of SensorInfo 
8. We declare a List of SensorInfo 
9. Now we check each sensor one by one: 
First Accelerometer 
10. Now we check each sensor one by one: 
then Light
Android Sensors Test 
11. Now we check each sensor one by one: 
First Magnetic field 
12. Now we check each sensor one by one: 
then Orientation
Android Sensors Test 
13. Now we check each sensor one by one: 
First Orientation Raw 
14. Now we check each sensor one by one: 
then Proximity
Android Sensors Test 
15. Now we check each sensor one by one: 
First Temperature 
16. Now we check each sensor one by one: 
then Tricorder
Android Sensors Test 
17. To show the list we do the following by setting adapter 
Now we run the app in emulator. 
Except Accelerometer we see all sensors are disabled 
May be in later SDKs we’ll get more enabled sensors
Android Sensors Test 
Lets run this in Galaxy tab 
We see the following are enabled: 
1. Accelerometer 
2. Light 
3. Magnetic Field 
4. Orientation 
5. Orientation Raw 
6. Proximity 
So the sensor support varies from 
Vendor to vendor and model to model
Android Sensor Programming 
As we see that Accelerometer is the 
1. most commonly used sensor and also 
2. it has many applications in games development, 
We’ll see and example of Sensor programming with Accelerometer 
And as we don’t have option to move the emulator we may have to use a 
sensor simulator which will simulate the sensor data. 
So we download the library for sensorsimulation at: 
http://openintents.googlecode.com/files/sensorsimulator-1.1.0-rc1.zip 
http://code.google.com/p/openintents/downloads/detail?name=sensorsimulator-1.1.0-rc1.zip&can=2&q= 
http://code.google.com/p/openintents/wiki/SensorSimulator 
We can follow their instruction to use it. 
But here, we’ll do it in our real device, so simulator will not be required
Create a project as an example 
We create a layout with a simple image 
which will move according to the 
Accelerometer:
Our Activity
Android Sensor Programming 
Adding SensorEventListener inner class with data update
Android Sensor Programming 
Declaring variables and registering listener
Android Sensor Programming 
Register and unregister listener on activity onStop and onResume:

More Related Content

PDF
Sensors and location based services
PDF
Sensors on android
PPTX
Android Training (Sensors)
PDF
Android Sensors
PPT
Android Sensor System
PPSX
Sensor's inside
ODP
Android sensors
PPTX
Android Sensor and Framework - AWARE
Sensors and location based services
Sensors on android
Android Training (Sensors)
Android Sensors
Android Sensor System
Sensor's inside
Android sensors
Android Sensor and Framework - AWARE

What's hot (20)

PPT
Smartphone sensor and gesture
PPTX
Peno sensor
PPTX
Design of Arduino based fire fighting Robot
PPT
Fire fighting robot using 8051 microcontroller
PDF
Generic sensors for the Web
DOCX
Automatic Altitude Control of Quadroto3
PPTX
fire fighting robot
PPTX
Human presence detection based room light controller using pir2.pptx [repaired]
PPTX
Automatic fire fighting robot
PPTX
Fire Fighting Robot
PPTX
Mebin progress
PPT
Fire Fighting Robot by saurabh
PPTX
Human Detection Robot
PDF
IRJET- Fire Fighting Robot using Arduino
PDF
IRJET-Android Controlled Firefighting Robot using Arduino
PPTX
Fire fighting robot ppt
PPTX
Different types of sensors
PPTX
Fire fighting robot
DOCX
Syn ankit
PPTX
Fire sensing robo
Smartphone sensor and gesture
Peno sensor
Design of Arduino based fire fighting Robot
Fire fighting robot using 8051 microcontroller
Generic sensors for the Web
Automatic Altitude Control of Quadroto3
fire fighting robot
Human presence detection based room light controller using pir2.pptx [repaired]
Automatic fire fighting robot
Fire Fighting Robot
Mebin progress
Fire Fighting Robot by saurabh
Human Detection Robot
IRJET- Fire Fighting Robot using Arduino
IRJET-Android Controlled Firefighting Robot using Arduino
Fire fighting robot ppt
Different types of sensors
Fire fighting robot
Syn ankit
Fire sensing robo
Ad

Viewers also liked (18)

PPTX
Android - Sensor Manager
PDF
Gradle Introduction
PPT
Introduction to sensors
PPT
Sensors and their applications
PPTX
Top sensors inside the smartphone you want to know
PPT
Sensors
DOCX
Smart Systems and The Future of Smart Products_ Group 4_FinalPaper (1)
PDF
Finding sensor related energy black holes in smartphone applications
PDF
Environmental Sensor Network Paper
PDF
Review Paper on Smart Sensor Network for Air Quality Monitoring
PDF
Get Moving with Core Motion
PPTX
Location based services
PPT
Post-PC: Geolocation & Maps in the Android Ecosystem
PPTX
Sensors 9
PDF
Head First XML Layout on Android
PDF
Draft activity recognition from accelerometer data
PPTX
Husky Lines Mobile App: Adapting transportation studies to our changing techn...
Android - Sensor Manager
Gradle Introduction
Introduction to sensors
Sensors and their applications
Top sensors inside the smartphone you want to know
Sensors
Smart Systems and The Future of Smart Products_ Group 4_FinalPaper (1)
Finding sensor related energy black holes in smartphone applications
Environmental Sensor Network Paper
Review Paper on Smart Sensor Network for Air Quality Monitoring
Get Moving with Core Motion
Location based services
Post-PC: Geolocation & Maps in the Android Ecosystem
Sensors 9
Head First XML Layout on Android
Draft activity recognition from accelerometer data
Husky Lines Mobile App: Adapting transportation studies to our changing techn...
Ad

Similar to Android Sensor (20)

PPTX
Android 1.8 sensor
PDF
Sensors in Android (old)
PDF
Week12.pdf
PDF
Android tutorial1
PPTX
Everything About Android - Itvedant, Thane | Mumbai | Navi Mumbai
DOCX
Control-Project
PPT
Synapseindia android apps development tutorial
PPT
Synapseindia android application development tutorial
PPT
cpuk10745
PDF
Android sensor
PDF
SMART BUNK BED CHILD MONITORING SYSTEM.pdf
ODP
Ppt 2 android_basics
PDF
Android 8 behavior changes
PPTX
Aptech Apps
PDF
Diving into VS 2015 Day2
PDF
React Native: Is It Worth It? UA Mobile 2017.
PPTX
Android location and sensors API
PDF
Android interview questions and answers
PDF
Android tutorial
PPTX
Game controlling via android
Android 1.8 sensor
Sensors in Android (old)
Week12.pdf
Android tutorial1
Everything About Android - Itvedant, Thane | Mumbai | Navi Mumbai
Control-Project
Synapseindia android apps development tutorial
Synapseindia android application development tutorial
cpuk10745
Android sensor
SMART BUNK BED CHILD MONITORING SYSTEM.pdf
Ppt 2 android_basics
Android 8 behavior changes
Aptech Apps
Diving into VS 2015 Day2
React Native: Is It Worth It? UA Mobile 2017.
Android location and sensors API
Android interview questions and answers
Android tutorial
Game controlling via android

More from nationalmobileapps (17)

PPTX
PPTX
Android Location Api
PPTX
Play Store
PPT
GCM (push notification)
PPTX
PPTX
Broadcast Receiver
PPTX
Google Map V2
PPTX
PPTX
Activity & Shared Preference
PPTX
PPTX
Support Multiple Screen
PPT
PPTX
Android UI
PPTX
Event Handling
PPTX
Project anatomy & hello world
PPTX
Mobile Application capacity building activities
PPTX
Future of Smart phone in Bangladesh
Android Location Api
Play Store
GCM (push notification)
Broadcast Receiver
Google Map V2
Activity & Shared Preference
Support Multiple Screen
Android UI
Event Handling
Project anatomy & hello world
Mobile Application capacity building activities
Future of Smart phone in Bangladesh

Recently uploaded (20)

PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
RMMM.pdf make it easy to upload and study
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Complications of Minimal Access Surgery at WLH
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
master seminar digital applications in india
PPTX
Cell Types and Its function , kingdom of life
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PDF
Pre independence Education in Inndia.pdf
PPH.pptx obstetrics and gynecology in nursing
RMMM.pdf make it easy to upload and study
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Microbial diseases, their pathogenesis and prophylaxis
Complications of Minimal Access Surgery at WLH
O7-L3 Supply Chain Operations - ICLT Program
TR - Agricultural Crops Production NC III.pdf
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Microbial disease of the cardiovascular and lymphatic systems
master seminar digital applications in india
Cell Types and Its function , kingdom of life
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
GDM (1) (1).pptx small presentation for students
Final Presentation General Medicine 03-08-2024.pptx
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
Pre independence Education in Inndia.pdf

Android Sensor

  • 1. Android application development Sensor Programming
  • 2. Android Sensors 1. Android phones support different sensors. 2. Today we write test code that reports which sensors our Android device supports. 3. Unfortunately, the emulator supports none upto SDK 1.5. 4. But we’ll see how many sensors are supported in real device 5. We’ll create a project named SensorTest for this. We’ll test following sensor list: 1. Accelerometer 2. Light 3. Magnetic Field 4. Orientation 5. Orientation Raw 6. Proximity 7. Temperature 8. Tricorder This is for SDK 1.5
  • 3. Let’s create a project named SensorTest
  • 4. Activity to a ListActivity 1. We change our Activity to a ListActivity
  • 5. Android Sensors Test 2. We’ll use SensorManager class 3. So we declare a List for SensorInfo 4. SensorInfo is a class defined by us which holds the sensor name and a boolean value whether its supported or not. 5. So we create a SensorInfo class
  • 6. ListActivity 6. Let’s get back to our ListActivity 7. We’ll now populate the list with all sensors and check whether they are enabled
  • 7. Declare a List of SensorInfo 8. We declare a List of SensorInfo 9. Now we check each sensor one by one: First Accelerometer 10. Now we check each sensor one by one: then Light
  • 8. Android Sensors Test 11. Now we check each sensor one by one: First Magnetic field 12. Now we check each sensor one by one: then Orientation
  • 9. Android Sensors Test 13. Now we check each sensor one by one: First Orientation Raw 14. Now we check each sensor one by one: then Proximity
  • 10. Android Sensors Test 15. Now we check each sensor one by one: First Temperature 16. Now we check each sensor one by one: then Tricorder
  • 11. Android Sensors Test 17. To show the list we do the following by setting adapter Now we run the app in emulator. Except Accelerometer we see all sensors are disabled May be in later SDKs we’ll get more enabled sensors
  • 12. Android Sensors Test Lets run this in Galaxy tab We see the following are enabled: 1. Accelerometer 2. Light 3. Magnetic Field 4. Orientation 5. Orientation Raw 6. Proximity So the sensor support varies from Vendor to vendor and model to model
  • 13. Android Sensor Programming As we see that Accelerometer is the 1. most commonly used sensor and also 2. it has many applications in games development, We’ll see and example of Sensor programming with Accelerometer And as we don’t have option to move the emulator we may have to use a sensor simulator which will simulate the sensor data. So we download the library for sensorsimulation at: http://openintents.googlecode.com/files/sensorsimulator-1.1.0-rc1.zip http://code.google.com/p/openintents/downloads/detail?name=sensorsimulator-1.1.0-rc1.zip&can=2&q= http://code.google.com/p/openintents/wiki/SensorSimulator We can follow their instruction to use it. But here, we’ll do it in our real device, so simulator will not be required
  • 14. Create a project as an example We create a layout with a simple image which will move according to the Accelerometer:
  • 16. Android Sensor Programming Adding SensorEventListener inner class with data update
  • 17. Android Sensor Programming Declaring variables and registering listener
  • 18. Android Sensor Programming Register and unregister listener on activity onStop and onResume: