SlideShare a Scribd company logo
1 of 27
Hack your Business with 
android and beacons 
Tushar Choudhary 
Mobile consultant, Xebia
Agenda 
Beacons- What, Why & How? 
Communication between Android & Beacons 
Android Libraries 
Android code- How to make an app with beacons 
Case Study- Employee Tracker 
Technical Pitfalls
Beacons : What are they? How they 
work? Why are they important ?
What are Beacons ? 
• Beacons are small piece of hardware 
devices that can emit and receive BLE 
signals.
Beacons
Why are they so important? 
• Broadcasting range 
• proximity
Communication b/w Android & 
Beacons
Communication between Android & 
Beacons 
• Bluetooth Low Energy (BLE)
Using BLE in Android 
•Permissions 
<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="true"/> 
// Use this check to determine whether BLE is supported on the device. Then 
// you can selectively disable BLE-related features. 
if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { 
Toast.makeText(this, R.string.ble_not_supported, Toast.LENGTH_SHORT).show(); 
finish(); 
}
Using BLE in Android 
•Setting Up BLE 
// Initializes Bluetooth adapter. 
final BluetoothManager bluetoothManager = 
(BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); 
mBluetoothAdapter = bluetoothManager.getAdapter(); 
private BluetoothAdapter mBluetoothAdapter; 
... 
// Ensures Bluetooth is available on the device and it is enabled. If not, 
// displays a dialog requesting user permission to enable Bluetooth. 
if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) { 
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); 
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); 
}
Using BLE in Android 
• Finding BLE Devices 
/** 
* Activity for scanning and displaying available BLE devices. 
*/ 
public class DeviceScanActivity extends ListActivity { 
private BluetoothAdapter mBluetoothAdapter; 
private boolean mScanning; 
private Handler mHandler; 
// Stops scanning after 10 seconds. 
private static final long SCAN_PERIOD = 10000; 
... 
private void scanLeDevice(final boolean enable) { 
if (enable) { 
// Stops scanning after a pre-defined scan period. 
mHandler.postDelayed(new Runnable() { 
@Override 
public void run() { 
mScanning = false; 
mBluetoothAdapter.stopLeScan(mLeScanCallback); 
} 
}, SCAN_PERIOD); 
mScanning = true; 
mBluetoothAdapter.startLeScan(mLeScanCallback); 
} else { 
mScanning = false; 
mBluetoothAdapter.stopLeScan(mLeScanCallback); 
} 
...
Using BLE in Android 
• Connecting to a GATT Server 
/ A service that interacts with the BLE device via the Android BLE API. 
public class BluetoothLeService extends Service { 
// Various callback methods defined by the BLE API. 
private final BluetoothGattCallback mGattCallback = 
private final static String TAG = BluetoothLeService.class.getSimpleName(); 
private BluetoothManager mBluetoothManager; 
private BluetoothAdapter mBluetoothAdapter; 
private String mBluetoothDeviceAddress; 
private BluetoothGatt mBluetoothGatt; 
private int mConnectionState = STATE_DISCONNECTED; 
private static final int STATE_DISCONNECTED = 0; 
private static final int STATE_CONNECTING = 1; 
private static final int STATE_CONNECTED = 2; 
public final static String ACTION_GATT_CONNECTED = 
"com.example.bluetooth.le.ACTION_GATT_CONNECTED"; 
public final static String ACTION_GATT_DISCONNECTED = 
"com.example.bluetooth.le.ACTION_GATT_DISCONNECTED"; 
public final static String ACTION_GATT_SERVICES_DISCOVERED = 
"com.example.bluetooth.le.ACTION_GATT_SERVICES_DISCOVERED"; 
public final static String ACTION_DATA_AVAILABLE = 
"com.example.bluetooth.le.ACTION_DATA_AVAILABLE"; 
public final static String EXTRA_DATA = 
"com.example.bluetooth.le.EXTRA_DATA"; 
public final static UUID UUID_HEART_RATE_MEASUREMENT = 
UUID.fromString(SampleGattAttributes.HEART_RATE_MEASUREMENT); 
new BluetoothGattCallback() { 
@Override 
public void onConnectionStateChange(BluetoothGatt gatt, int status, 
int newState) { 
String intentAction; 
if (newState == BluetoothProfile.STATE_CONNECTED) { 
intentAction = ACTION_GATT_CONNECTED; 
mConnectionState = STATE_CONNECTED; 
broadcastUpdate(intentAction); 
Log.i(TAG, "Connected to GATT server."); 
Log.i(TAG, "Attempting to start service discovery:" + 
mBluetoothGatt.discoverServices()); 
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) { 
intentAction = ACTION_GATT_DISCONNECTED; 
mConnectionState = STATE_DISCONNECTED; 
Log.i(TAG, "Disconnected from GATT server."); 
broadcastUpdate(intentAction); 
} 
} 
@Override 
// New services discovered 
public void onServicesDiscovered(BluetoothGatt gatt, int status) { 
if (status == BluetoothGatt.GATT_SUCCESS) { 
broadcastUpdate(ACTION_GATT_SERVICES_DISCOVERED); 
} else { 
Log.w(TAG, "onServicesDiscovered received: " + status); 
} 
} 
@Override 
// Result of a characteristic read operation 
public void onCharacteristicRead(BluetoothGatt gatt, 
BluetoothGattCharacteristic characteristic, 
int status) { 
if (status == BluetoothGatt.GATT_SUCCESS) { 
broadcastUpdate(ACTION_DATA_AVAILABLE, characteristic); 
} 
} 
... 
}; 
... 
}
Using BLE in Android 
• Reading BLE attributes 
public class DeviceControlActivity extends Activity { 
... 
// Demonstrates how to iterate through the supported GATT 
// Services/Characteristics. 
// In this sample, we populate the data structure that is bound to the 
// ExpandableListView on the UI. 
private void displayGattServices(List<BluetoothGattService> gattServices) { 
if (gattServices == null) return; 
String uuid = null; 
String unknownServiceString = getResources(). 
getString(R.string.unknown_service); 
String unknownCharaString = getResources(). 
getString(R.string.unknown_characteristic); 
ArrayList<HashMap<String, String>> gattServiceData = 
new ArrayList<HashMap<String, String>>(); 
ArrayList<ArrayList<HashMap<String, String>>> gattCharacteristicData 
= new ArrayList<ArrayList<HashMap<String, String>>>(); 
mGattCharacteristics = 
new ArrayList<ArrayList<BluetoothGattCharacteristic>>(); 
// Loops through available GATT Services. 
for (BluetoothGattService gattService : gattServices) { 
HashMap<String, String> currentServiceData = 
new HashMap<String, String>(); 
uuid = gattService.getUuid().toString(); 
currentServiceData.put( 
LIST_NAME, SampleGattAttributes. 
lookup(uuid, unknownServiceString)); 
currentServiceData.put(LIST_UUID, uuid); 
gattServiceData.add(currentServiceData); 
ArrayList<HashMap<String, String>> 
gattCharacteristicGroupData = 
new ArrayList<HashMap<String, String>>(); 
List<BluetoothGattCharacteristic> gattCharacteristics = 
gattService.getCharacteristics(); 
ArrayList<BluetoothGattCharacteristic> charas = 
new ArrayList<BluetoothGattCharacteristic>(); 
// Loops through available Characteristics. 
for (BluetoothGattCharacteristic gattCharacteristic : 
gattCharacteristics) { 
charas.add(gattCharacteristic); 
HashMap<String, String> currentCharaData = 
new HashMap<String, String>(); 
uuid = gattCharacteristic.getUuid().toString(); 
currentCharaData.put( 
LIST_NAME, SampleGattAttributes.lookup(uuid, 
unknownCharaString)); 
currentCharaData.put(LIST_UUID, uuid); 
gattCharacteristicGroupData.add(currentCharaData); 
} 
mGattCharacteristics.add(charas); 
gattCharacteristicData.add(gattCharacteristicGroupData); 
} 
... 
} 
... 
}
Beacons/BLE : How They Work ? 
• BLE enabled devices or Beacons can 
transmits small packets of data. 
• This wakes up a “listener/receiver” to let it 
know that it’s there. 
• Which then lets you calculate the proximity 
to the Beacon and show relevant 
information to visitors.
Android Libraries
Android Beacons & Support Libraries 
Android Beacon Library: 
https://github.com/AltBeacon/android-beacon-library-reference 
Smart Gatt Library: 
https://github.com/movisens/SmartGattLib 
Bluetooth LE Library Android: 
https://github.com/alt236/Bluetooth-LE-Library---Android
Android code- How to make an 
app with beacons
Building the Android App 
1. Implement a broadcast receiver to catch 
broadcasts for turning bluetooth on and off. 
2. Start a service when bluetooth turns on. 
3. Stop service when bluetooth turns off 
4. Register a listener to listen for nearby beacon 
devices
Implementing Broadcast Receiver 
@Override 
public void onReceive(Context context, Intent intent) { 
// TODO Auto-generated method stub 
if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(intent.getAction())) { 
int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1); 
Intent i; 
switch (state) { 
case BluetoothAdapter.STATE_OFF: 
if (MyBeaconService.isStarted) { 
i = new Intent(context, 
MyBeaconIntentService.class); 
i.putExtra("StartBeaconService", false); 
context.stopService(i); 
} 
Log.i(TAG, "Bluetooth State : OFF"); 
break; 
case BluetoothAdapter.STATE_ON: 
Log.i(TAG, "Bluetooth State : ON"); 
if (!MyBeaconService.isStarted) { 
i = new Intent(context, 
MyBeaconIntentService.class); 
i.putExtra("StartBeaconService", true); 
context.startService(i); 
} 
break; 
} 
} 
}
Registering Ranging Listener in 
Service’s onCreate() method 
@Override 
public void onCreate() { 
super.onCreate(); 
beaconManager.setMonitoringListener(new 
BeaconManager.MonitoringListener() { 
@Override 
public void onExitedRegion(Region arg0) { 
// TODO Auto-generated method stub 
Util.postNotification(getBaseContext(), 
"Alert Luggage Tracker", 
notificationManager, 1, 
AllDemosActivity.class); 
} 
@Override 
public void onEnteredRegion(Region arg0, List<Beacon> arg1) 
{ 
// TODO Auto-generated method stub 
}}); 
}
Connecting to BeaconManager’s Service 
in Service’s onStartCommand() 
@Override 
public int onStartCommand(Intent intent, int flags, int startId) { 
beaconManager.connect(new BeaconManager.ServiceReadyCallback() { 
@Override 
public void onServiceReady() { 
try { 
beaconManager.startMonitoring(BEACONS); 
} catch (RemoteException e) { 
Log.e(TAG, "Cannot start ranging", e); 
} catch (Exception e) { 
e.printStackTrace(); 
} 
} 
}); 
return START_NOT_STICKY; 
}
Case Study
Xebia Employee Tracker 
• Xebia Employee tracker maps real time positions of 
my company’s employees on a 2d map 
• Any employee at any time can see position of other 
colleagues on the map 
• Cool data analytics are applied to show interesting 
results such as- max crowd time in cafeteria in a day, 
An employee’s location heat map for a day :D
Xebia Employee Tracker 
{{ Show Case Xebia Employee Tracker }} 
{{ Show Source Code }}
Technical Pitfalls
Technical pitfalls of Android + Beacons ? 
• Bluetooth must be turned on. 
• Your app must be installed on users devices. 
• You can't trigger mobile beacon or iBeacon to trigger 
installation of an app. 
• Location services must be enabled for the specific 
application. 
• To download real data we must have an app 
connected via internet connection.
Thank You!

More Related Content

Similar to Android & Beacons

Assistive Technology_Research
Assistive Technology_ResearchAssistive Technology_Research
Assistive Technology_ResearchMeng Kry
 
A brief overview of BLE on Android
A brief overview of BLE on AndroidA brief overview of BLE on Android
A brief overview of BLE on AndroidLuka Bašek
 
What's new in android jakarta gdg (2015-08-26)
What's new in android   jakarta gdg (2015-08-26)What's new in android   jakarta gdg (2015-08-26)
What's new in android jakarta gdg (2015-08-26)Google
 
JSR 82 (bluetooth obex)
JSR 82 (bluetooth obex)JSR 82 (bluetooth obex)
JSR 82 (bluetooth obex)SMIJava
 
MCE^3 - Dariusz Seweryn, Paweł Urban - Demystifying Android's Bluetooth Low ...
MCE^3 - Dariusz Seweryn, Paweł Urban -  Demystifying Android's Bluetooth Low ...MCE^3 - Dariusz Seweryn, Paweł Urban -  Demystifying Android's Bluetooth Low ...
MCE^3 - Dariusz Seweryn, Paweł Urban - Demystifying Android's Bluetooth Low ...PROIDEA
 
Demystifying Android's Bluetooth Low Energy at MCE^3 Conf
Demystifying Android's Bluetooth Low Energy at MCE^3 ConfDemystifying Android's Bluetooth Low Energy at MCE^3 Conf
Demystifying Android's Bluetooth Low Energy at MCE^3 ConfPawel Urban
 
Android Wi-Fi Manager and Bluetooth Connection
Android Wi-Fi Manager and Bluetooth ConnectionAndroid Wi-Fi Manager and Bluetooth Connection
Android Wi-Fi Manager and Bluetooth ConnectionJussi Pohjolainen
 
Fiware IoT Proposal & Community
Fiware IoT Proposal & Community Fiware IoT Proposal & Community
Fiware IoT Proposal & Community TIDChile
 
Mini project final presentation
Mini project final presentationMini project final presentation
Mini project final presentationGianlucaCapozzi1
 
What's new in Android P @ I/O Extended Bangkok 2018
What's new in Android P @ I/O Extended Bangkok 2018What's new in Android P @ I/O Extended Bangkok 2018
What's new in Android P @ I/O Extended Bangkok 2018Somkiat Khitwongwattana
 
Mobile Development for Devices and IoT
Mobile Development for Devices and IoTMobile Development for Devices and IoT
Mobile Development for Devices and IoTWes Bailey
 
Google Wave API: Now and Beyond
Google Wave API: Now and BeyondGoogle Wave API: Now and Beyond
Google Wave API: Now and BeyondMarakana Inc.
 
Everything About Bluetooth (淺談藍牙 4.0) - Central 篇
Everything About Bluetooth (淺談藍牙 4.0) - Central 篇Everything About Bluetooth (淺談藍牙 4.0) - Central 篇
Everything About Bluetooth (淺談藍牙 4.0) - Central 篇Johnny Sung
 
Android Workshop
Android WorkshopAndroid Workshop
Android WorkshopJunda Ong
 
Reaching out from ADF Mobile (ODTUG KScope 2014)
Reaching out from ADF Mobile (ODTUG KScope 2014)Reaching out from ADF Mobile (ODTUG KScope 2014)
Reaching out from ADF Mobile (ODTUG KScope 2014)Luc Bors
 
Easy2park - A smarter way to find a parking lot
Easy2park - A smarter way to find a parking lotEasy2park - A smarter way to find a parking lot
Easy2park - A smarter way to find a parking lotDaniele Davoli
 
HyWAI Web Bluetooth API
HyWAI Web Bluetooth APIHyWAI Web Bluetooth API
HyWAI Web Bluetooth APIJonathan Jeon
 

Similar to Android & Beacons (20)

Eddystone beacons demo
Eddystone beacons demoEddystone beacons demo
Eddystone beacons demo
 
Assistive Technology_Research
Assistive Technology_ResearchAssistive Technology_Research
Assistive Technology_Research
 
A brief overview of BLE on Android
A brief overview of BLE on AndroidA brief overview of BLE on Android
A brief overview of BLE on Android
 
What's new in android jakarta gdg (2015-08-26)
What's new in android   jakarta gdg (2015-08-26)What's new in android   jakarta gdg (2015-08-26)
What's new in android jakarta gdg (2015-08-26)
 
JSR 82 (bluetooth obex)
JSR 82 (bluetooth obex)JSR 82 (bluetooth obex)
JSR 82 (bluetooth obex)
 
MCE^3 - Dariusz Seweryn, Paweł Urban - Demystifying Android's Bluetooth Low ...
MCE^3 - Dariusz Seweryn, Paweł Urban -  Demystifying Android's Bluetooth Low ...MCE^3 - Dariusz Seweryn, Paweł Urban -  Demystifying Android's Bluetooth Low ...
MCE^3 - Dariusz Seweryn, Paweł Urban - Demystifying Android's Bluetooth Low ...
 
Demystifying Android's Bluetooth Low Energy at MCE^3 Conf
Demystifying Android's Bluetooth Low Energy at MCE^3 ConfDemystifying Android's Bluetooth Low Energy at MCE^3 Conf
Demystifying Android's Bluetooth Low Energy at MCE^3 Conf
 
Android Wi-Fi Manager and Bluetooth Connection
Android Wi-Fi Manager and Bluetooth ConnectionAndroid Wi-Fi Manager and Bluetooth Connection
Android Wi-Fi Manager and Bluetooth Connection
 
Fiware IoT Proposal & Community
Fiware IoT Proposal & Community Fiware IoT Proposal & Community
Fiware IoT Proposal & Community
 
Mini project final presentation
Mini project final presentationMini project final presentation
Mini project final presentation
 
What's new in Android P @ I/O Extended Bangkok 2018
What's new in Android P @ I/O Extended Bangkok 2018What's new in Android P @ I/O Extended Bangkok 2018
What's new in Android P @ I/O Extended Bangkok 2018
 
Mobile Development for Devices and IoT
Mobile Development for Devices and IoTMobile Development for Devices and IoT
Mobile Development for Devices and IoT
 
Google Wave API: Now and Beyond
Google Wave API: Now and BeyondGoogle Wave API: Now and Beyond
Google Wave API: Now and Beyond
 
Integrando sua app Android com Chromecast
Integrando sua app Android com ChromecastIntegrando sua app Android com Chromecast
Integrando sua app Android com Chromecast
 
Everything About Bluetooth (淺談藍牙 4.0) - Central 篇
Everything About Bluetooth (淺談藍牙 4.0) - Central 篇Everything About Bluetooth (淺談藍牙 4.0) - Central 篇
Everything About Bluetooth (淺談藍牙 4.0) - Central 篇
 
Android Workshop
Android WorkshopAndroid Workshop
Android Workshop
 
Reaching out from ADF Mobile (ODTUG KScope 2014)
Reaching out from ADF Mobile (ODTUG KScope 2014)Reaching out from ADF Mobile (ODTUG KScope 2014)
Reaching out from ADF Mobile (ODTUG KScope 2014)
 
Easy2park - A smarter way to find a parking lot
Easy2park - A smarter way to find a parking lotEasy2park - A smarter way to find a parking lot
Easy2park - A smarter way to find a parking lot
 
HyWAI Web Bluetooth API
HyWAI Web Bluetooth APIHyWAI Web Bluetooth API
HyWAI Web Bluetooth API
 
Developing in android
Developing in androidDeveloping in android
Developing in android
 

Recently uploaded

Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 

Recently uploaded (20)

Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 

Android & Beacons

  • 1. Hack your Business with android and beacons Tushar Choudhary Mobile consultant, Xebia
  • 2. Agenda Beacons- What, Why & How? Communication between Android & Beacons Android Libraries Android code- How to make an app with beacons Case Study- Employee Tracker Technical Pitfalls
  • 3. Beacons : What are they? How they work? Why are they important ?
  • 4. What are Beacons ? • Beacons are small piece of hardware devices that can emit and receive BLE signals.
  • 6. Why are they so important? • Broadcasting range • proximity
  • 8. Communication between Android & Beacons • Bluetooth Low Energy (BLE)
  • 9. Using BLE in Android •Permissions <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="true"/> // Use this check to determine whether BLE is supported on the device. Then // you can selectively disable BLE-related features. if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { Toast.makeText(this, R.string.ble_not_supported, Toast.LENGTH_SHORT).show(); finish(); }
  • 10. Using BLE in Android •Setting Up BLE // Initializes Bluetooth adapter. final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); mBluetoothAdapter = bluetoothManager.getAdapter(); private BluetoothAdapter mBluetoothAdapter; ... // Ensures Bluetooth is available on the device and it is enabled. If not, // displays a dialog requesting user permission to enable Bluetooth. if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); }
  • 11. Using BLE in Android • Finding BLE Devices /** * Activity for scanning and displaying available BLE devices. */ public class DeviceScanActivity extends ListActivity { private BluetoothAdapter mBluetoothAdapter; private boolean mScanning; private Handler mHandler; // Stops scanning after 10 seconds. private static final long SCAN_PERIOD = 10000; ... private void scanLeDevice(final boolean enable) { if (enable) { // Stops scanning after a pre-defined scan period. mHandler.postDelayed(new Runnable() { @Override public void run() { mScanning = false; mBluetoothAdapter.stopLeScan(mLeScanCallback); } }, SCAN_PERIOD); mScanning = true; mBluetoothAdapter.startLeScan(mLeScanCallback); } else { mScanning = false; mBluetoothAdapter.stopLeScan(mLeScanCallback); } ...
  • 12. Using BLE in Android • Connecting to a GATT Server / A service that interacts with the BLE device via the Android BLE API. public class BluetoothLeService extends Service { // Various callback methods defined by the BLE API. private final BluetoothGattCallback mGattCallback = private final static String TAG = BluetoothLeService.class.getSimpleName(); private BluetoothManager mBluetoothManager; private BluetoothAdapter mBluetoothAdapter; private String mBluetoothDeviceAddress; private BluetoothGatt mBluetoothGatt; private int mConnectionState = STATE_DISCONNECTED; private static final int STATE_DISCONNECTED = 0; private static final int STATE_CONNECTING = 1; private static final int STATE_CONNECTED = 2; public final static String ACTION_GATT_CONNECTED = "com.example.bluetooth.le.ACTION_GATT_CONNECTED"; public final static String ACTION_GATT_DISCONNECTED = "com.example.bluetooth.le.ACTION_GATT_DISCONNECTED"; public final static String ACTION_GATT_SERVICES_DISCOVERED = "com.example.bluetooth.le.ACTION_GATT_SERVICES_DISCOVERED"; public final static String ACTION_DATA_AVAILABLE = "com.example.bluetooth.le.ACTION_DATA_AVAILABLE"; public final static String EXTRA_DATA = "com.example.bluetooth.le.EXTRA_DATA"; public final static UUID UUID_HEART_RATE_MEASUREMENT = UUID.fromString(SampleGattAttributes.HEART_RATE_MEASUREMENT); new BluetoothGattCallback() { @Override public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { String intentAction; if (newState == BluetoothProfile.STATE_CONNECTED) { intentAction = ACTION_GATT_CONNECTED; mConnectionState = STATE_CONNECTED; broadcastUpdate(intentAction); Log.i(TAG, "Connected to GATT server."); Log.i(TAG, "Attempting to start service discovery:" + mBluetoothGatt.discoverServices()); } else if (newState == BluetoothProfile.STATE_DISCONNECTED) { intentAction = ACTION_GATT_DISCONNECTED; mConnectionState = STATE_DISCONNECTED; Log.i(TAG, "Disconnected from GATT server."); broadcastUpdate(intentAction); } } @Override // New services discovered public void onServicesDiscovered(BluetoothGatt gatt, int status) { if (status == BluetoothGatt.GATT_SUCCESS) { broadcastUpdate(ACTION_GATT_SERVICES_DISCOVERED); } else { Log.w(TAG, "onServicesDiscovered received: " + status); } } @Override // Result of a characteristic read operation public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { if (status == BluetoothGatt.GATT_SUCCESS) { broadcastUpdate(ACTION_DATA_AVAILABLE, characteristic); } } ... }; ... }
  • 13. Using BLE in Android • Reading BLE attributes public class DeviceControlActivity extends Activity { ... // Demonstrates how to iterate through the supported GATT // Services/Characteristics. // In this sample, we populate the data structure that is bound to the // ExpandableListView on the UI. private void displayGattServices(List<BluetoothGattService> gattServices) { if (gattServices == null) return; String uuid = null; String unknownServiceString = getResources(). getString(R.string.unknown_service); String unknownCharaString = getResources(). getString(R.string.unknown_characteristic); ArrayList<HashMap<String, String>> gattServiceData = new ArrayList<HashMap<String, String>>(); ArrayList<ArrayList<HashMap<String, String>>> gattCharacteristicData = new ArrayList<ArrayList<HashMap<String, String>>>(); mGattCharacteristics = new ArrayList<ArrayList<BluetoothGattCharacteristic>>(); // Loops through available GATT Services. for (BluetoothGattService gattService : gattServices) { HashMap<String, String> currentServiceData = new HashMap<String, String>(); uuid = gattService.getUuid().toString(); currentServiceData.put( LIST_NAME, SampleGattAttributes. lookup(uuid, unknownServiceString)); currentServiceData.put(LIST_UUID, uuid); gattServiceData.add(currentServiceData); ArrayList<HashMap<String, String>> gattCharacteristicGroupData = new ArrayList<HashMap<String, String>>(); List<BluetoothGattCharacteristic> gattCharacteristics = gattService.getCharacteristics(); ArrayList<BluetoothGattCharacteristic> charas = new ArrayList<BluetoothGattCharacteristic>(); // Loops through available Characteristics. for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) { charas.add(gattCharacteristic); HashMap<String, String> currentCharaData = new HashMap<String, String>(); uuid = gattCharacteristic.getUuid().toString(); currentCharaData.put( LIST_NAME, SampleGattAttributes.lookup(uuid, unknownCharaString)); currentCharaData.put(LIST_UUID, uuid); gattCharacteristicGroupData.add(currentCharaData); } mGattCharacteristics.add(charas); gattCharacteristicData.add(gattCharacteristicGroupData); } ... } ... }
  • 14. Beacons/BLE : How They Work ? • BLE enabled devices or Beacons can transmits small packets of data. • This wakes up a “listener/receiver” to let it know that it’s there. • Which then lets you calculate the proximity to the Beacon and show relevant information to visitors.
  • 16. Android Beacons & Support Libraries Android Beacon Library: https://github.com/AltBeacon/android-beacon-library-reference Smart Gatt Library: https://github.com/movisens/SmartGattLib Bluetooth LE Library Android: https://github.com/alt236/Bluetooth-LE-Library---Android
  • 17. Android code- How to make an app with beacons
  • 18. Building the Android App 1. Implement a broadcast receiver to catch broadcasts for turning bluetooth on and off. 2. Start a service when bluetooth turns on. 3. Stop service when bluetooth turns off 4. Register a listener to listen for nearby beacon devices
  • 19. Implementing Broadcast Receiver @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(intent.getAction())) { int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1); Intent i; switch (state) { case BluetoothAdapter.STATE_OFF: if (MyBeaconService.isStarted) { i = new Intent(context, MyBeaconIntentService.class); i.putExtra("StartBeaconService", false); context.stopService(i); } Log.i(TAG, "Bluetooth State : OFF"); break; case BluetoothAdapter.STATE_ON: Log.i(TAG, "Bluetooth State : ON"); if (!MyBeaconService.isStarted) { i = new Intent(context, MyBeaconIntentService.class); i.putExtra("StartBeaconService", true); context.startService(i); } break; } } }
  • 20. Registering Ranging Listener in Service’s onCreate() method @Override public void onCreate() { super.onCreate(); beaconManager.setMonitoringListener(new BeaconManager.MonitoringListener() { @Override public void onExitedRegion(Region arg0) { // TODO Auto-generated method stub Util.postNotification(getBaseContext(), "Alert Luggage Tracker", notificationManager, 1, AllDemosActivity.class); } @Override public void onEnteredRegion(Region arg0, List<Beacon> arg1) { // TODO Auto-generated method stub }}); }
  • 21. Connecting to BeaconManager’s Service in Service’s onStartCommand() @Override public int onStartCommand(Intent intent, int flags, int startId) { beaconManager.connect(new BeaconManager.ServiceReadyCallback() { @Override public void onServiceReady() { try { beaconManager.startMonitoring(BEACONS); } catch (RemoteException e) { Log.e(TAG, "Cannot start ranging", e); } catch (Exception e) { e.printStackTrace(); } } }); return START_NOT_STICKY; }
  • 23. Xebia Employee Tracker • Xebia Employee tracker maps real time positions of my company’s employees on a 2d map • Any employee at any time can see position of other colleagues on the map • Cool data analytics are applied to show interesting results such as- max crowd time in cafeteria in a day, An employee’s location heat map for a day :D
  • 24. Xebia Employee Tracker {{ Show Case Xebia Employee Tracker }} {{ Show Source Code }}
  • 26. Technical pitfalls of Android + Beacons ? • Bluetooth must be turned on. • Your app must be installed on users devices. • You can't trigger mobile beacon or iBeacon to trigger installation of an app. • Location services must be enabled for the specific application. • To download real data we must have an app connected via internet connection.