SlideShare uma empresa Scribd logo
1 de 18
Android Application Development
       Sensor Programming




                                      Ahsanul Karim
                        ahsanul.karim@sentinelbd.com
                              Sentinel Solutions Ltd.
                            http://www.sentinelbd.com
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
Sensor Programming
Android Sensors Test
 We create a project named SensorTest
Sensor Programming
Android Sensors Test
 1. We change our Activity to a ListActivity
Sensor Programming
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
Sensor Programming
Android Sensors Test
 6. Let’s get back to our ListActivity




  7. We’ll now populate the list with all sensors and check whether they are enabled
Sensor Programming
Android Sensors Test
 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
Sensor Programming
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
Sensor Programming
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
Sensor Programming
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
Sensor Programming
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
Sensor Programming
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
Sensor Programming
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
Sensor Programming
Android Sensor Programming
 Let’s create a project as an example   We create a layout with a simple image
                                        which will move according to the
                                        Accelerometer:
Sensor Programming
Android Sensor Programming
 Our Activity:
Sensor Programming
Android Sensor Programming
  Adding SensorEventListener inner class with data update
Sensor Programming
Android Sensor Programming
 Declaring variables and registering listener
Sensor Programming
Android Sensor Programming
  Register and unregister listener on activity onStop and onResume:

Mais conteúdo relacionado

Mais procurados

Introduction to Android Development: Before Getting Started
Introduction to Android Development: Before Getting StartedIntroduction to Android Development: Before Getting Started
Introduction to Android Development: Before Getting StartedAhsanul Karim
 
Multiple Activity and Navigation Primer
Multiple Activity and Navigation PrimerMultiple Activity and Navigation Primer
Multiple Activity and Navigation PrimerAhsanul Karim
 
Android MapView and MapActivity
Android MapView and MapActivityAndroid MapView and MapActivity
Android MapView and MapActivityAhsanul Karim
 
Day 1 Android: Before Getting Started
Day 1 Android: Before Getting StartedDay 1 Android: Before Getting Started
Day 1 Android: Before Getting StartedAhsanul Karim
 
লেকচার ১ (ক)- শুরুর আগে:
লেকচার ১ (ক)- শুরুর আগে:লেকচার ১ (ক)- শুরুর আগে:
লেকচার ১ (ক)- শুরুর আগে:Ahsanul Karim
 
Day 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesDay 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesAhsanul Karim
 
Android application-component
Android application-componentAndroid application-component
Android application-componentLy Haza
 
Marakana Android User Interface
Marakana Android User InterfaceMarakana Android User Interface
Marakana Android User InterfaceMarko Gargenta
 
What’s new in Xcode 8? – Future of Native App Development Opportunities
What’s new in Xcode 8? – Future of Native App Development OpportunitiesWhat’s new in Xcode 8? – Future of Native App Development Opportunities
What’s new in Xcode 8? – Future of Native App Development OpportunitiesRigel Networks LLC
 
Day1 before getting_started
Day1 before getting_startedDay1 before getting_started
Day1 before getting_startedAhsanul Karim
 
Create your First Watchkit App
Create your First Watchkit AppCreate your First Watchkit App
Create your First Watchkit AppPawan Ramteke
 
Android Development: Build Android App from Scratch
Android Development: Build Android App from ScratchAndroid Development: Build Android App from Scratch
Android Development: Build Android App from ScratchTaufan Erfiyanto
 

Mais procurados (20)

Introduction to Android Development: Before Getting Started
Introduction to Android Development: Before Getting StartedIntroduction to Android Development: Before Getting Started
Introduction to Android Development: Before Getting Started
 
Multiple Activity and Navigation Primer
Multiple Activity and Navigation PrimerMultiple Activity and Navigation Primer
Multiple Activity and Navigation Primer
 
Training android
Training androidTraining android
Training android
 
Android MapView and MapActivity
Android MapView and MapActivityAndroid MapView and MapActivity
Android MapView and MapActivity
 
Day 1 Android: Before Getting Started
Day 1 Android: Before Getting StartedDay 1 Android: Before Getting Started
Day 1 Android: Before Getting Started
 
লেকচার ১ (ক)- শুরুর আগে:
লেকচার ১ (ক)- শুরুর আগে:লেকচার ১ (ক)- শুরুর আগে:
লেকচার ১ (ক)- শুরুর আগে:
 
Day 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesDay 3: Getting Active Through Activities
Day 3: Getting Active Through Activities
 
Android application-component
Android application-componentAndroid application-component
Android application-component
 
Marakana Android User Interface
Marakana Android User InterfaceMarakana Android User Interface
Marakana Android User Interface
 
cpuk10745
cpuk10745cpuk10745
cpuk10745
 
Android
AndroidAndroid
Android
 
What’s new in Xcode 8? – Future of Native App Development Opportunities
What’s new in Xcode 8? – Future of Native App Development OpportunitiesWhat’s new in Xcode 8? – Future of Native App Development Opportunities
What’s new in Xcode 8? – Future of Native App Development Opportunities
 
Android session 2
Android session 2Android session 2
Android session 2
 
Android session 1
Android session 1Android session 1
Android session 1
 
Day1 before getting_started
Day1 before getting_startedDay1 before getting_started
Day1 before getting_started
 
Android session 3
Android session 3Android session 3
Android session 3
 
Android course (lecture2)
Android course (lecture2)Android course (lecture2)
Android course (lecture2)
 
Create your First Watchkit App
Create your First Watchkit AppCreate your First Watchkit App
Create your First Watchkit App
 
Android
AndroidAndroid
Android
 
Android Development: Build Android App from Scratch
Android Development: Build Android App from ScratchAndroid Development: Build Android App from Scratch
Android Development: Build Android App from Scratch
 

Destaque

Day 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViewsDay 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViewsAhsanul Karim
 
Android GPS Tutorial
Android GPS TutorialAndroid GPS Tutorial
Android GPS TutorialAhsanul Karim
 
Android Workshop: Day 1 Part 3
Android Workshop: Day 1 Part 3Android Workshop: Day 1 Part 3
Android Workshop: Day 1 Part 3Ahsanul Karim
 
Day 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through ActivitiesDay 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through ActivitiesAhsanul Karim
 
Creating the first app with android studio
Creating the first app with android studioCreating the first app with android studio
Creating the first app with android studioParinita03
 
Lecture 1 Session 1 Before Getting Started
Lecture 1 Session 1 Before Getting StartedLecture 1 Session 1 Before Getting Started
Lecture 1 Session 1 Before Getting StartedAhsanul Karim
 
Android Workshop Day 1 Part 2
Android Workshop Day 1 Part 2Android Workshop Day 1 Part 2
Android Workshop Day 1 Part 2Ahsanul Karim
 
Ui layout (incomplete)
Ui layout (incomplete)Ui layout (incomplete)
Ui layout (incomplete)Ahsanul Karim
 
Android before getting started
Android before getting startedAndroid before getting started
Android before getting startedAhsanul Karim
 
Day 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesDay 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesAhsanul Karim
 

Destaque (14)

Day 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViewsDay 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViews
 
List Views
List ViewsList Views
List Views
 
Android GPS Tutorial
Android GPS TutorialAndroid GPS Tutorial
Android GPS Tutorial
 
Android Workshop: Day 1 Part 3
Android Workshop: Day 1 Part 3Android Workshop: Day 1 Part 3
Android Workshop: Day 1 Part 3
 
Day 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through ActivitiesDay 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through Activities
 
Creating the first app with android studio
Creating the first app with android studioCreating the first app with android studio
Creating the first app with android studio
 
Lecture 1 Session 1 Before Getting Started
Lecture 1 Session 1 Before Getting StartedLecture 1 Session 1 Before Getting Started
Lecture 1 Session 1 Before Getting Started
 
Android Workshop Day 1 Part 2
Android Workshop Day 1 Part 2Android Workshop Day 1 Part 2
Android Workshop Day 1 Part 2
 
Mcq peresentation
Mcq  peresentationMcq  peresentation
Mcq peresentation
 
GCM for Android
GCM for AndroidGCM for Android
GCM for Android
 
Client-Server
Client-ServerClient-Server
Client-Server
 
Ui layout (incomplete)
Ui layout (incomplete)Ui layout (incomplete)
Ui layout (incomplete)
 
Android before getting started
Android before getting startedAndroid before getting started
Android before getting started
 
Day 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesDay 3: Getting Active Through Activities
Day 3: Getting Active Through Activities
 

Semelhante a Android Application Development - Sensor Programming

Sensors on android
Sensors on androidSensors on android
Sensors on androidChinmay V S
 
Everything About Android - Itvedant, Thane | Mumbai | Navi Mumbai
Everything About Android - Itvedant, Thane | Mumbai | Navi Mumbai Everything About Android - Itvedant, Thane | Mumbai | Navi Mumbai
Everything About Android - Itvedant, Thane | Mumbai | Navi Mumbai Itvedant
 
Synapseindia android application development tutorial
Synapseindia android application development tutorialSynapseindia android application development tutorial
Synapseindia android application development tutorialSynapseindiappsdevelopment
 
Synapseindia android apps development tutorial
Synapseindia android apps  development tutorialSynapseindia android apps  development tutorial
Synapseindia android apps development tutorialSynapseindiappsdevelopment
 
Android app developers in bangalore- thorsignia
Android app developers in bangalore- thorsigniaAndroid app developers in bangalore- thorsignia
Android app developers in bangalore- thorsigniacharan Teja
 
Android location and sensors API
Android location and sensors APIAndroid location and sensors API
Android location and sensors APIeleksdev
 
Wireless sensor networks using android virtual devices and near field
Wireless sensor networks using android virtual devices and near fieldWireless sensor networks using android virtual devices and near field
Wireless sensor networks using android virtual devices and near fieldNicolas Kockel
 
Android AppDevelopment
Android AppDevelopmentAndroid AppDevelopment
Android AppDevelopmentAshraf Ali
 
Android app Development Prepration Tips
Android app Development Prepration TipsAndroid app Development Prepration Tips
Android app Development Prepration TipsYasmeen Sheikh
 
Android Development in a Nutshell
Android Development in a NutshellAndroid Development in a Nutshell
Android Development in a NutshellAleix Solé
 
Easy steps to develop android application (tutorial)
Easy steps to develop android application (tutorial)Easy steps to develop android application (tutorial)
Easy steps to develop android application (tutorial)Dewan Razib
 

Semelhante a Android Application Development - Sensor Programming (20)

Android Sensor
Android SensorAndroid Sensor
Android Sensor
 
Sensors on android
Sensors on androidSensors on android
Sensors on android
 
Week12.pdf
Week12.pdfWeek12.pdf
Week12.pdf
 
Everything About Android - Itvedant, Thane | Mumbai | Navi Mumbai
Everything About Android - Itvedant, Thane | Mumbai | Navi Mumbai Everything About Android - Itvedant, Thane | Mumbai | Navi Mumbai
Everything About Android - Itvedant, Thane | Mumbai | Navi Mumbai
 
Synapseindia android application development tutorial
Synapseindia android application development tutorialSynapseindia android application development tutorial
Synapseindia android application development tutorial
 
Synapseindia android apps development tutorial
Synapseindia android apps  development tutorialSynapseindia android apps  development tutorial
Synapseindia android apps development tutorial
 
Android tutorial1
Android tutorial1Android tutorial1
Android tutorial1
 
Android app developers in bangalore- thorsignia
Android app developers in bangalore- thorsigniaAndroid app developers in bangalore- thorsignia
Android app developers in bangalore- thorsignia
 
Android Sensors
Android SensorsAndroid Sensors
Android Sensors
 
Game controlling via android
Game controlling via androidGame controlling via android
Game controlling via android
 
Control-Project
Control-ProjectControl-Project
Control-Project
 
Android location and sensors API
Android location and sensors APIAndroid location and sensors API
Android location and sensors API
 
Wireless sensor networks using android virtual devices and near field
Wireless sensor networks using android virtual devices and near fieldWireless sensor networks using android virtual devices and near field
Wireless sensor networks using android virtual devices and near field
 
Android AppDevelopment
Android AppDevelopmentAndroid AppDevelopment
Android AppDevelopment
 
QR Code Scanner
QR Code Scanner QR Code Scanner
QR Code Scanner
 
Android sensor
Android sensorAndroid sensor
Android sensor
 
Aptech Apps
Aptech Apps Aptech Apps
Aptech Apps
 
Android app Development Prepration Tips
Android app Development Prepration TipsAndroid app Development Prepration Tips
Android app Development Prepration Tips
 
Android Development in a Nutshell
Android Development in a NutshellAndroid Development in a Nutshell
Android Development in a Nutshell
 
Easy steps to develop android application (tutorial)
Easy steps to develop android application (tutorial)Easy steps to develop android application (tutorial)
Easy steps to develop android application (tutorial)
 

Mais de Ahsanul Karim

Lecture 5: Storage: Saving Data Database, Files & Preferences
Lecture 5: Storage: Saving Data Database, Files & PreferencesLecture 5: Storage: Saving Data Database, Files & Preferences
Lecture 5: Storage: Saving Data Database, Files & PreferencesAhsanul Karim
 
Day 15: Content Provider: Using Contacts API
Day 15: Content Provider: Using Contacts APIDay 15: Content Provider: Using Contacts API
Day 15: Content Provider: Using Contacts APIAhsanul Karim
 
Day 9: Make Your App Location Aware using Location API
Day 9: Make Your App Location Aware using Location APIDay 9: Make Your App Location Aware using Location API
Day 9: Make Your App Location Aware using Location APIAhsanul Karim
 
Day 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViewsDay 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViewsAhsanul Karim
 
Day 5: Android User Interface [View Widgets]
Day 5: Android User Interface [View Widgets]Day 5: Android User Interface [View Widgets]
Day 5: Android User Interface [View Widgets]Ahsanul Karim
 
Day 4: Activity lifecycle
Day 4: Activity lifecycleDay 4: Activity lifecycle
Day 4: Activity lifecycleAhsanul Karim
 
Mobile Banking in Bangladesh: An Incomplete Study
Mobile Banking in Bangladesh: An Incomplete StudyMobile Banking in Bangladesh: An Incomplete Study
Mobile Banking in Bangladesh: An Incomplete StudyAhsanul Karim
 
Action Bar Sherlock tutorial
Action Bar Sherlock tutorialAction Bar Sherlock tutorial
Action Bar Sherlock tutorialAhsanul Karim
 

Mais de Ahsanul Karim (9)

Lecture 5: Storage: Saving Data Database, Files & Preferences
Lecture 5: Storage: Saving Data Database, Files & PreferencesLecture 5: Storage: Saving Data Database, Files & Preferences
Lecture 5: Storage: Saving Data Database, Files & Preferences
 
Day 15: Content Provider: Using Contacts API
Day 15: Content Provider: Using Contacts APIDay 15: Content Provider: Using Contacts API
Day 15: Content Provider: Using Contacts API
 
Day 9: Make Your App Location Aware using Location API
Day 9: Make Your App Location Aware using Location APIDay 9: Make Your App Location Aware using Location API
Day 9: Make Your App Location Aware using Location API
 
Day 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViewsDay 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViews
 
Day 5: Android User Interface [View Widgets]
Day 5: Android User Interface [View Widgets]Day 5: Android User Interface [View Widgets]
Day 5: Android User Interface [View Widgets]
 
Day 4: Activity lifecycle
Day 4: Activity lifecycleDay 4: Activity lifecycle
Day 4: Activity lifecycle
 
Mobile Banking in Bangladesh: An Incomplete Study
Mobile Banking in Bangladesh: An Incomplete StudyMobile Banking in Bangladesh: An Incomplete Study
Mobile Banking in Bangladesh: An Incomplete Study
 
AndroidManifest
AndroidManifestAndroidManifest
AndroidManifest
 
Action Bar Sherlock tutorial
Action Bar Sherlock tutorialAction Bar Sherlock tutorial
Action Bar Sherlock tutorial
 

Último

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 

Último (20)

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 

Android Application Development - Sensor Programming

  • 1. Android Application Development Sensor Programming Ahsanul Karim ahsanul.karim@sentinelbd.com Sentinel Solutions Ltd. http://www.sentinelbd.com
  • 2. 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
  • 3. Sensor Programming Android Sensors Test We create a project named SensorTest
  • 4. Sensor Programming Android Sensors Test 1. We change our Activity to a ListActivity
  • 5. Sensor Programming 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. Sensor Programming Android Sensors Test 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. Sensor Programming Android Sensors Test 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. Sensor Programming 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. Sensor Programming 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. Sensor Programming 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. Sensor Programming 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. Sensor Programming 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. Sensor Programming 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. Sensor Programming Android Sensor Programming Let’s create a project as an example We create a layout with a simple image which will move according to the Accelerometer:
  • 15. Sensor Programming Android Sensor Programming Our Activity:
  • 16. Sensor Programming Android Sensor Programming Adding SensorEventListener inner class with data update
  • 17. Sensor Programming Android Sensor Programming Declaring variables and registering listener
  • 18. Sensor Programming Android Sensor Programming Register and unregister listener on activity onStop and onResume: