Android : BluetoothAdapter.LeScanCallback

介绍

Android 4.3(API 18)及以上

android.bluetooth.BluetoothAdapter.LeScanCallback

调用BluetoothAdapter.startLeScan(LeScanCallback)BluetoothAdapter.startLeScan(UUID[], LeScanCallback)的回调接口,用于传送 BLE 蓝牙的查找结果。

抽象方法:

public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord)

注意事项

onLeScan 方法在Android 5.0以下及Android 5.0及以上所运行的线程不同。

private BluetoothAdapter.LeScanCallback leScanCallback = new BluetoothAdapter.LeScanCallback() {
    @Override
    public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord) {
        if (Looper.myLooper() == Looper.getMainLooper()) {
            // Android 5.0 及以上
            connect(device);
        } else {
            // Android 5.0 以下
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    connect(device);
                }
            });
        }
    }
};

你可能感兴趣的:(Android)