蓝牙低功耗在Android上无法正常工作

时间:2017-08-22 15:26:06

标签: android bluetooth bluetooth-lowenergy android-bluetooth

我正在使用蓝牙低功耗的分布式系统来定位他们在建筑物中的用户。到目前为止,我们使用Android手机作为外围设备在不同的会议室中宣传不同的信息。

一切似乎都运转良好但我们发现三星S5(SM-G900M)的问题是找到我们的广告(我们使用ScanFilters来检测外围设备)但ScanRecord带有空值或空值。相同的代码在Pixel和Samsung S7上运行良好。

这是我们的广告代码:

private AdvertiseData createFMPAdvertiseData() {
    AdvertiseData.Builder builder = new AdvertiseData.Builder();
    builder.addServiceUuid(new ParcelUuid(UUID.fromString("d0acdb90-745a-42a9-8e4d-9de4fb9342dc")));
    return builder.build();
}

private static AdvertiseSettings createAdvSettings(boolean connectable, int timeoutMillis) {
    AdvertiseSettings.Builder builder = new AdvertiseSettings.Builder();
    builder.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED);

    // Connectable true
    builder.setConnectable(connectable);
    builder.setTimeout(timeoutMillis);
    builder.setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_HIGH);
    return builder.build();
} 

mBluetoothLeAdvertiser.startAdvertising(
                createAdvSettings(true, 0),
                createFMPAdvertiseData(),
                mAdvertiseCallback);

这是我们的扫描码:

public ScanSettings createScanSettings() {
        ScanSettings.Builder builder = new ScanSettings.Builder();
        builder.setCallbackType(ScanSettings.CALLBACK_TYPE_FIRST_MATCH | ScanSettings.CALLBACK_TYPE_MATCH_LOST);
        builder.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY);
        builder.setMatchMode(ScanSettings.MATCH_MODE_AGGRESSIVE);

        return builder.build();
    }

    public void setCallbacks() {
        // Device scan callback.
        mScanCallback = new ScanCallback() {
            @Override
            public void onScanResult(int callbackType, ScanResult result) {
                Log.i(TAG, "RSSI" + result.getRssi());
                BluetoothDevice device = result.getDevice();
                Log.i(TAG, "Device " + device.getAddress() + ", Callback type: " + callbackType);
                ScanRecord record = result.getScanRecord();
                Log.i(TAG, "uuid data" + record.getServiceData());
                Log.i(TAG, "bytes" + byteArrayToHex(record.getBytes()));
                UUID uuid = record.getServiceUuids().get(0).getUuid();
                Log.i(TAG, "uuid" + record.getServiceUuids());

Samsung S5正在运行Android 6.0.1。 任何帮助将不胜感激。

0 个答案:

没有答案