AndroidGPS, Location Services, Camera and [email protected]
Today’s agenda
GPS and Location Services
Using Google Play Services
Camera
Sensors
***
GPS and Location Services
How GPS Works
Global Positioning System (GPS) - mechanism to get location coordinates (latitude and longitude) by directly connecting to satellites.
GPS radio (Hardware) present in every smartphone.
When turned ON, GPS radio communicates with at least 3 satellites and tries to calculate its location.
Choose either COARSE or FINE location.
How GPS Works
Location Services in Android - Old Way
LocationManager
● Get last known location● Request frequent location updates - LocationListener
GeoCoder
● Get complete street address from geo coordinates● Get geo coordinates from street address
LocationListener
Two methods:
● onLocationChanged()● onStatusChanged()
Things to consider:
● Type of location provider● Minimum time interval for next update● Minimum distance covered before next update
Services - Demo
Using Google’s Location Services - The new way
“Provides same functionality and more in better and more efficient way using least battery.”
● Getting last known location● Receiving location updates● Displaying location address
Google Play Services
Google Play Games Services
Location APIs
Google+ APIs
Maps
Google Drive APIs
Google Wallet, Google Ads, Google Fit and many more..
Using Google Play Services for Location
Handling google API Client
Getting Location Updates
Create
Using Maps
Add Google Maps in app.
Show required location/address in map.
Draw Marker on map.
Zoom to a particular location.
Show address related information in map.
Using Maps
SupportMapFragment:
Using Maps - Other Important Classes
GoogleMap
LatLng
MarkerOptions
CameraUpdate
Demo
Sensors
Sensors in Android
To detect device movement: rotation, acceleration, orientation.
To detect environmental conditions: temperature or humidity.
● Motion sensors● Environment sensors● Position sensors
Motion & Position Sensors
Accelerometer
Gravity Sensor
Gyroscope
Rotation Sensor
Orientation Sensor
Magnetometer
Gyroscope
Sensors
Using Sensors in App
Working on every individual sensor separately is not required.
Many sensors are combined to form one sensor. E.g. Accelerometer, gyroscope and orientation sensors work together to give meaningful and usable values.
Access sensor available on device using “Sensor” class in Android.
● Determine which sensors are available● Retrieve raw sensor data● Register and unregister sensor event listeners
Using Sensors in App
Android Sensor Framework
SensorManager
Sensor
SensorEvent
SensorEventListener
Demo
Camera
Camera in Android
Take Picture or Record Video, apply filters, use in-built camera features.
Either built Camera feature in App from scratch using Framework classes:
● Android.hardware.camera2● Camera● SurfaceView● MediaRecorder
Or use Intent to open in-built camera app to take picture.
Using Intent to Open Camera App
Compose Camera Intent.
Start Camera Activity.
Receive clicked picture as a result from Intent.
Demo
Content Providers
Content Providers
A layer above stored data.
Hide how data is stored.
Used to share data between apps.
Provide Security to stored data.
Provide standard interface to access data easily.
Examples of In-built Content Providers
Calendar Provider
Contacts Provider
Browser History and bookmarks
User Dictionary
Call logs
Making Queries
Making Query - Using Cursor
Projection
Demo
Paramvir Singh
Android Architect and Trainer
+91-9999703899