Agenda€¦ · Beacons & GPS Case Study Android & Beacons Dummy App • • • BLE. Security...

Post on 18-Aug-2020

1 views 0 download

transcript

Agenda

What, Why & How

Bluetooth versus BLE

Beacons & GPS

Case Study

Android & Beacons

Dummy App

BLE

Security Equipments

Advantage to Developers

Before BLE After BLE

An app would need to be running in the foreground or background to communicate with a BLE device.

An app can be launched into background if a specific BLE device is recognized.

••

••

••

•••

Use Case : Luggage Tracker

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

@Overridepublic void onCreate() {

super.onCreate();

beaconManager.setMonitoringListener(new BeaconManager.MonitoringListener() {

@Overridepublic void onExitedRegion(Region arg0) {

// TODO Auto-generated method stubUtil.postNotification(getBaseContext(),

"Alert Luggage Tracker",notificationManager, 1,AllDemosActivity.class);

}

@Overridepublic 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() {

@Overridepublic 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;}