matchinguu droidcon presentation
TRANSCRIPT
LOCATION BASED SOLUTIONS IN THE ANDROID REALM There are many ways to Rome, some may look quite surprising Jürgen Fey . CTO matchinguu
AGENDA
• Matchinguu backgrounder • Loca2on Provider Technologies for Android devices • Use cases
SOME INFO ABOUT US
WE ARE THE EXPERT FOR ”LOCATION BASED SOLUTIONS” WITH THE CLEAR FOCUS ON MOBILE. matchinguu is a startup based in Munich, Germany (headcount: 9+). We started in 2013 with a clear target: matchinguu is providing a comprehensive API for Android and iOS as well as the needed backend services and hardware infrastructure to allow businesses to integrate even complex LBS scenarios fast. Yes, we also built complete, custom apps.
OUR SERVICES
ANDROID API Easy to integrate API for various loca2on providers. Event system. Power management.
iOS API Easy to integrate API for various loca2on providers. Event system. Power management. BACKEND SaaS
Customer dashboard to control loca2ons and events. Heatmaps, Process automa2on, repor2ng and more…
HARDWARE Local hotspot, business intelligence, Beacons, Backend adapters and more .
LOCATION PROVIDERS ON MOBILE PLATFORMS
CELL-ID
WLAN
GPS
FUSED LOCATION PROVIDER
GEOHASH
SENSORS
GEOFENCES
BEACONS
IOT
NFC
Many op(ons The mobile plaSorm (Android) provides a wide range of LBS op2ons. Combine and/or use wisely While one might be tempted to use the best providers at any given 2me just to be save the user will not tolerate the resul2ng power drain.
CELL-ID
If the mobile device is connected to a network cell (through the modem part) the „Cell-‐ID“ provides a clear loca2on fingerprint • The network base sta2ons (Base Transceiver Sta2on, Cell) are sta2c
loca2on reference points • The loca2ons are known to the providers, Google and other service
providers • Triangula2on allows one to guess a loca2on with smaller error burden Accuracy: From < 100m to > 20 km Public Cell-‐ID databases
OpenCellID (h_p://wiki.opencellid.org/wiki/API) unwiredlabs Loca2onAPI (h_p://unwiredlabs.com/)
CELL-ID
Use TelephonyManager to retrieve current • CellID • MNC (Mobile Network Code) • MCC (Mobile Country Code) • LAC (Loca2on Area Code) Use PhoneStateListener and onCellInfoChanged callback to retrieve new Cell-‐ID info (device must be awake! wakelock) Power Factor: very low, for constant background updates higher Android Reference: h_p://developer.android.com/reference/android/telephony/CellLoca2on.html
CELL-ID
Example TelephonyManager tManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); GsmCellLocation cellLocation = (GsmCellLocation)tManager.getCellLocation(); String networkOperator = tManager.getNetworkOperator(); String mcc = networkOperator.substring(0, 3); String mnc = networkOperator.substring(3); int cid = cellLocation.getCid(); int lac = cellLocation.getLac();
CELL-ID
Nice Android appS: • OpenSignal • Cell WIDGET
CELL-ID
Sidenote: By using an IMSI catcher (you might Google for that one...) an en2ty other than the official provider may „provide“ you with an alterna2ve Cell, which takes over the task of network connec2vity. IMSI catcher detec2on: h_p://forum.xda-‐developers.com/showthread.php?t=1422969
WLAN
The WLAN signal is a perfect reference for quite accurate loca2on info. How does Google get this valuable info?
It´s YOU! Add the following ingredients to the sweet cake: • Android Device • GPS and other Loca2on Providers • Network connec2on No need to use Maps etc – they do it anyways (occasionally, anonymously) BTW: Apple, Microsok et al are working the same way Public Database: h_p://www.openwlanmap.org/
WLAN
Each WLAN Access Point can be defined by • SSID (Service Set Iden2fier) • MAC Address (unique network hardware address)
By merging the info about an SSID and all other Loca2on Providers (when available) it is possible to build up a Loca2on Database using just SSIDs. This is what is happening – each SSID can/may be used for Loca2on info Known SSIDs can be used for inhouse apps (Custom WLAN Proximity) Power Factor: high when always on, „manageable“ for proximity use case Android Tutorial: h_p://www.tutorialspoint.com/android/android_wi_fi.htm
GEOHASH
GeoHashing is using a specially prepared text info for high accurary loca2on. A single GeoHash string provides info for a two coordinate loca2on Depending on the string length the accuracy increases 8 characters: 38/19m 12 characters: 4/2 cm
h_p://unterbahn.com/2009/11/metric-‐dimensions-‐of-‐geohash-‐par22ons-‐at-‐the-‐equator/
GEOHASH
GEOHASH
GEOHASH
Example: h_p://geohash.org/u33d8m58g (Gleisdreieck Berlin) Some databases support GeoHashing (MongoDB, SOLR etc.) Matchinguu uses the GeoHash info as part of the SSID for customer APs SSID: „magic_u33d8m58g_zH232J_powered by matchinguu“ Anyone interested to provide an open source repo for such kind of locSSID? (lets talk) Nice demo: h_p://geohash.gofreerange.com/
GPS
The „bread-‐and-‐bu_er“ Loca2on provider. Dedicated GPS hardware Accuracy for public uses cases: down to 3m Update rate: down to 1s TTFF (Time To First Fix): may take loooong
needs to „see“ at least 3 satellites – the more the be_er usually in less than a minute, but s2ll ...
Power Factor: very high (80..150 mA) Android Example: h_p://www.codeproject.com/Ar2cles/665527/A-‐GPS-‐Loca2on-‐Ploqng-‐Android-‐Applica2on
GPS
For GPS and any other loca2on providers: Use BroadcastReceiver or Service with LocaEonListener to set up true background processing. BroadcastReceiver: Android adds your receiver during boot 2me (if listed in Manifest). Quite nice for apps working in background. Alterna2ve: Register during run2me and send an PendingIndent . This is be_er when you need to cope with states. Service: Generally a bit heavier but s2ll also ok.
GPS
Unofficial features: <uses-permission android:name=„android.permission.ACCESS_LOCATION_EXTRACOMMANDS“ />
http://androidxref.com/
GPS
When used wisely, GPS is a top notch provider for accurate loca2on informa2on – use it wisely and only when needed and you are save. Do not use it as the sole source, if possible. Always keep the power consump2on in mind. GPS must be turned on – in case you need to ask the user to ac2vate.
SENSORS
Sensors are playing an increasingly important role when dealing with loca2on-‐aware solu2ons. They may be used to help „guessing“ movements, hence a new loca2on – or just to reduce power consump2on. There are three general sensor groups supported by Android: • Mo2on sensors
• Accelerometer • Gravity • Gyroscope/Rota2onal Vector
• Environmental sensors • Temperatur • Light/Sound • Air Pressure/Humidity
• Posi2on sensors • Orienta2on • Magnetometer
SENSORS
The number of available sensors, their capabili2es and accuracy does vary! There is no thing as a generic sensor in each category. There might be mul2ple sensors per category – with different behavior. Lots of supliers for the same sensor category. Some sensors are sokware only – they are modelling the reality by using other sensors (accelera2on etc.). Source: EE Times
SENSORS
Access to the set of available sensors is provided by the SensorFramework. The sensor support started to be quite complete from API 9 (Android 2.3). SensorEventListener: • onAccurayChanged • onSensorChanged
SensorEvent provides the new set of data (sensor specific)
SENSORS
Sensors are also used to detect/infer user behavior: Significant Mo2on Sensor (SensorManager): „A significant mo1on is a mo1on that might lead to a change in the user's loca1on; for example walking, biking, or si@ng in a moving car.“ mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_SIGNIFICANT_MOTION); mTriggerEventListener = new TriggerEventListener() { @Override public void onTrigger(TriggerEvent event) { // Do work } }; mSensorManager.requestTriggerSensor(mTriggerEventListener, mSensor);
SENSORS
Google Play – 2013: new AcEvity RecogniEon feature to provide a best guess of the current user ac2vity. Based on sensor input. • ON_FOOT • IN_VEHICLE • ON_BYCICLE • STILL • TILTING • New: Running, Walking Generates results with a probability. Low power implementa2on – may be used instead of „homegrown“ solu2ons based on raw sensor data.
ANDROID LOCATION MANAGER
Loca2on Manager used to be the central instance to receive Loca2on info • GPS • Cell-‐ID • WLAN • Support from API 1 • No Play Store lib needed • App needs to ask explicitly • Some calc voodoo needed
ADDING SOME SENSOR INFO By adding addi2onal help from the sensors one might be able to be_er guess or actually know the current loca2on
HOMEBREW LOCATION SOLUTION
By using all of the shown loca2on provider sources it is possible to get a quite op2mized loca2on informa2on. Lots of needed support code Op2mizing the bets prac2ce parameters done by app developer
Parameters might be different on other hardware It is important to check for availability of each provider first Essen2al to cope with ongoing status changes (offline/online, on/off)
For most devices there is an alterna2ve: Fused Loca2on Provider
FUSED LOCATION PROVIDER
The Fused LocaEon Provider merges the available sources into one single source: • GPS • Cell-‐ID • WLAN • Sensors • Part of the Google Play package
• Not available on all devices! • If there is a Play Store app, there is the Play package • Cumbersome process to add into a rooted device.....
FUSED LOCATION PROVIDER
FUSED LOCATION PROVIDER
locRequest = Loca2onRequest.create() .setPriority (Loca2onRequest.BALANCED_POWER_ACCURACY) .setInterval(10000) // 10s .setExpira2onDura2on (120000) // stop aker 2 min from NOW .setSmallestDisplacement (25) // 25m min. movement for update .setNumUpdates (5) // stop aker 3 updates mLoca2onClient.requestLoca2onUpdates (locRequest, this)
FUSED LOCATION PROVIDER
Loca2onClient needs to implement • GooglePlayServicesClient.ConnecEonCallbacks • GooglePlayServices.onConnecEonFailedListener • LocaEonListner Callbacks: • onConnected • onDisconnected • onConnecEonFailed • onLocaEonChanged
FUSED LOCATION PROVIDER
Priority op2ons and power drain impact (Source: Google, Galaxy Nexus):
Priority Interval Drain (% per h) Accuracy
HIGH_ACCURACY 5s 7.25% ~10m
BALANCED_POWER 20s 0.6% ~40m
NO_POWER N/A small ~Cell related
FUSED LOCATION PROVIDER
I am here! No, i moved a bit. Now i am here. Wait, i am there.
FUSED LOCATION PROVIDER
Always check the accuracy value of ANY result before any further ac2on. Even if you get a 7 digit value you may s2ll be off quite a bit.
GEOFENCES
A GeoFence is just a radial area, defined by the loca2on center and the radius. As a result we get a virtual radial fence.
GEOFENCES – OLD STYLE
Homebrew version -‐ How one had to do it before(based on Loca2onManager): Intent intent = new Intent(PROX_ALERT_INTENT);
PendingIntent proximityIntent = PendingIntent.getBroadcast(this, intentnum, intent, 0);
locationManager.addProximityAlert(
latitude, longitude,
POINT_RADIUS,
PROX_ALERT_EXPIRATION, proximityIntent)
....
GEOFENCES – OLD STYLE
While the old style might look good it had one major drawback: It is using way to much ba_ery power. Reason: No control over loca2on request update parameters like update frequency or provider! The default implementa2on result in constant queries and your ba_ery will be cozy and warm – and soon empty. Solu2on: Implement your own GeoFence checker using onLocaEonChanged and some math (it‘s just points and circles) and issue an Intent yourself with LocaEonManager.KEY_PROXIMITY_ENTERING etc.
GEOFENCES
Now Google Play Services provide a new GeoFence feature. Just some easy steps: Define the central loca2on of the GeoFence. Then add the trigger event you like: • entering • leaving • both Add a lifespan (up to 6 days) Limit of 100 concurrently ac2ve GeoFences on Android Aker ac2va2on the GeoFence trigger will be able to start your app (running in background) to do whatever you like. No need to watch loca2on updates yourself Power footprint op2mized.
Google: 1/3 of addProximityAlert()
BEACONS
Everyone talks about iBeacons™ these days as THE indoor loca2on enabler. Apple ™ trademarked the term. Lets talk about Beacons then... Basic technology:
Bluetooth Low Energy (BLE) Bluetooth Smart NOT compa2ble with „normal“ BT Bluetooth Smart Ready (dual mode) GATT (Generic A_ribute Profile) send short a_ributes/data packets with specific UUID Two connec2on roles Central Peripheral Two communica2on roles Server Client
BEACONS
A central role BLE device is able to scan for other devices A peripheral device sends out „adver2sements“ A Server send out data – a client receives it
Blood pressure device is a peripheral and a server Android device is the central device and the data client
BEACONS
BEACONS
TI SensorTag -‐iBeacon support with license
BEACONS
BEACONS
IBEACONS
To use BLE for indoor purposes, loca2on etc in iBeacon mode: Device needs to be in adver2se mode to periodically sending out data
20ms .. 10s Data: 47 byte packages including (in PDU data part – 32 byte)
UUID unique ID (hopefully) Major group ID Minor individual ID TX power level
Apple requires hardware vendors to be a licensee: h_p://mfi.apple.com/
IBEACONS
Source: h_p://www.havlena.net/en/loca2on-‐technologies/ibeacons-‐how-‐do-‐they-‐technically-‐work/
BEACONS
Indoor loca2on: To measure the distance between the smartphone and an adver2sing beacon we use the received signal strength indica2on (RSSI) The TX value is the signal strength 1m away – used as the reference. To get the posi2on we need 2+ beacons and triangula2on. Nice star2ng point for android devs: h_ps://github.com/RadiusNetworks/android-‐ibeacon-‐service
BEACONS
Support on Android device just about to start. Only a few devices have it! OS minimum: iOS 5+, Windows Phone 8+, Android 4.3+, BB 10 Check for it: <uses-permission android:name="android.permission.BLUETOOTH"/> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN“/> <uses-feature android:name="android.hardware.bluetooth_le" android:required=“false"/> PackageManager pm = ctx.getPackageManager(); boolean hasBLE = pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE);
uses-‐feature false? ! app will install on all devices. Use the PM at run2me to access the feature anyways
DEMO
IOT
The Internet of Things is – at least for the mobile device -‐ just a wild bunch of „somewhat ac2ve tech“, which may be able to communicate. Is it? IoT device may communicate with the smartphone too! They just need to sit on common communica2on protocols.
BLE, NFC, WLAN, Radio... Since one may know the loca2on of an IoT device in the scanned area you will get one more loca2on provider.
IOT
BLE enabled Arduino devices (Cortado etc.) WLAN enabled Arduino devices (Sparc Core)
NFC
Even NFC could be used for loca2on purposes The NFC tag may hold loca2on data (GeoHash etc) user needs to be very close to the tag
USE CASES
1.) User walks by a store and receives an mighty coupon 10000 mile view: • Loca2on info for store • App checking the loca2on info • App asking the server what to do/or just knowing (eventAPI) what to do • App showing the coupon • User trades coupon for goods • Coupon is tracked to user/transac2on and may pay the app developer
USE CASES
Example of a simple mguAPI Event • API wakes up and ini2ates an Ac2vity view • Further ac2on are subject of customiza2on
USE CASES
2.) „The big drawing“ enabler • You want that one visitor in the stadium gets the big price (like shoo2ng at
the goal during half 2me) • User enters the GeoFenced stadium • App verifies that the loca2on is „inside“ • App sends a token to the server aker user interac2on • Server chooses one token and sends back the winning no2fica2on to the
winner with loca2on based instruc2ons where to meet the contact person.
• Winner is able to meet the contact, gets on the field ...
USE CASES
3.) Find your dog • Dog is wearing a small GPS/GPRS tag sending out loca2on info when
outside a GeoFence (not an Android app) • App receives the alarm data SMS with the loca2on • App leads the user to the dogs loca2on by using maps etc.
MATCHINGUU SERVICES
matchinguu provides a comprehensive API library for indoor and outdoor loca2on • all possible loca2on providers • power management • POI management via internal rules, biz logic and backend
matchinguu also provides the eventAPI • what to do when an event actually occurs? • Manage and market events
matchinguu provides the backend too • Support high numbers of POIs, beacons, customers, partners • Dashboard access for our partners
MATCHINGUU SERVICES
Indoor loca2on Heatmap display via dashboard
MATCHINGUU SERVICES
Dashboard 10000 mile view onto major data clusters
MATCHINGUU SERVICES
Dashboard • Gain access to current stats • Op2mize • React • Steer
MATCHINGUU SERVICES
Coming June 2014
ANDROID REFERENCES
Fused Loca2on: h_p://developer.android.com/training/loca2on/index.html Sensors: h_p://developer.android.com/guide/topics/sensors/sensors_overview.html h_ps://sokware.intel.com/en-‐us/ar2cles/developing-‐sensor-‐applica2ons-‐on-‐intel-‐atom-‐processor-‐based-‐android-‐phones-‐and-‐tablets Android Source Repo Xref: h_p://androidxref.com/ Book: (when you are allowed to take just one single book) Android Programming – Pushing the Limits (Erik Hellman) -‐ Wiley