btAdapter.isMultipleAdvertisementSupported()始终为假

时间:2019-10-21 15:55:34

标签: android altbeacon android-ibeacon

我需要模拟信标。我使用设备

  • Android 6.0(LG,Nexus 5)
  • Android 9.0(荣誉10)

在我的app / build.gradle中:

implementation 'org.altbeacon:android-beacon-library:2.16.3'

在我的活动中:

public void onClickGenerateBeacon(View view) {
        Beacon beacon = new Beacon.Builder()
                .setId1(UUID.randomUUID().toString())
                .setId2("1")
                .setId3("2")
                .setManufacturer(0x0118)
                .setTxPower(-59)
                .setDataFields(Arrays.asList(new Long[]{0l}))
                .build();
        BluetoothManager btManager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE);
        BluetoothAdapter btAdapter = btManager.getAdapter();
        boolean isSupported = false;
        if (btAdapter.isEnabled())
            isSupported = btAdapter.isMultipleAdvertisementSupported();

        if (isSupported) {
            BeaconParser beaconParser = new BeaconParser().setBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25");
            BeaconTransmitter beaconTransmitter = new BeaconTransmitter(getApplicationContext(), beaconParser);
            beaconTransmitter.startAdvertising(beacon);
        }
    }

但是 isSupported 始终为false。结果是不执行:

new BeaconParser().setBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25");

我该如何解决?是否可以通过此库模仿信标,或者有另一种方法?

1 个答案:

答案 0 :(得分:1)

不幸的是,无法使用这些手机上安装的Android操作系统来解决此问题。如果isMultipleAdvertisementSupported返回false,则操作系统本身会阻止BLE广告的传输。有关Nexus 5的说明,请参见here

理论上,您可以扎根Nexus 5并安装其他不会阻止BLE广告的ROM映像。根据我的经验,我知道Nexus 5的Android L beta 1版本确实允许广告。该ROM映像不再可以从Google获得,但是您可以找到其他可阻止Nexus 5的可安装ROM。

对于Huawei Honor设备,许多不支持广告,但其他一些则支持。这是一个略过时的table,显示了已知支持广告的广告。