Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android BLE Beacon scanning

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/

like image 861
Sven Haiges Avatar asked Sep 19 '13 08:09

Sven Haiges


2 Answers

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();
    }
like image 35
JackAW Avatar answered Sep 18 '22 17:09

JackAW


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.

like image 133
dull_boy Avatar answered Sep 20 '22 17:09

dull_boy