Bluetooth LE was added in Android 4.3 but it seems there is no background scanning mode which would wake up an app once it has registered to be notified via a available BLE UUID in proximity.
This exactly seems to be possible via iOS7 and iBeacons API. Does anyone know if there is such a feature in Android 4.3 or if there is a good workaround for periiodically scanning the BLE environment for BLE devices?
http://developer.android.com/guide/topics/connectivity/bluetooth-le.html
http://techcrunch.com/2013/09/11/estimote-details-ios-7-ibeacon-support-for-its-contextual-proximity-shopping-devices/
Directly from the android example, you can use a handler:
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);
invalidateOptionsMenu();
}
}, SCAN_PERIOD);
mScanning = true;
mBluetoothAdapter.startLeScan(mLeScanCallback);
} else {
mScanning = false;
mBluetoothAdapter.stopLeScan(mLeScanCallback);
}
invalidateOptionsMenu();
}
I think there is a workaround as below: You need to implement a service and create thread to while loop to call the mBluetoothAdapter.startLeScan(mLeScanCallback), then you can check whether be trigeed by specific device and further to search specific UUID.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With