Java 使用AltBeacon库以CoreBooth格式发布广告

Java 使用AltBeacon库以CoreBooth格式发布广告,java,android,bluetooth-lowenergy,core-bluetooth,altbeacon,Java,Android,Bluetooth Lowenergy,Core Bluetooth,Altbeacon,我正在尝试使用BLE实现Android和ios之间的跨操作系统广告和扫描功能。 我需要了解在Android设备上用CoreBooth做广告需要遵循的流程。 我一直在使用AltBeacon library以iBeacon格式进行广告宣传,效果很好,但ios无法扫描iBeacon上有限数量的信标,这迫使我转向CoreBooth框架 以下是我用来以iBeacon格式发布广告的示例代码: BluetoothManager bluetoothManager = (Bluetooth

我正在尝试使用BLE实现Android和ios之间的跨操作系统广告和扫描功能。 我需要了解在Android设备上用CoreBooth做广告需要遵循的流程。 我一直在使用AltBeacon library以iBeacon格式进行广告宣传,效果很好,但ios无法扫描iBeacon上有限数量的信标,这迫使我转向CoreBooth框架

以下是我用来以iBeacon格式发布广告的示例代码:

BluetoothManager bluetoothManager =
            (BluetoothManager) applicationContext.getSystemService(Context.BLUETOOTH_SERVICE);
    if (bluetoothManager != null) {
        BluetoothAdapter mBluetoothAdapter = bluetoothManager.getAdapter();
        BluetoothLeAdvertiser mBluetoothLeAdvertiser = mBluetoothAdapter.getBluetoothLeAdvertiser();
        if (mBluetoothLeAdvertiser != null) {
            beacon = new Beacon.Builder()
                    .setId1(userId)
                    .setId2("1")
                    .setId3("1")
                    .setManufacturer(0x004C)
                    .setTxPower(-75)
                    .setDataFields(Arrays.asList(new Long[]{0l}))
                    .build();
            beaconParser = new BeaconParser()
                    .setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24");
            beaconTransmitter = new BeaconTransmitter(InventaSdk.getContext(), beaconParser);
            beaconTransmitter.setBeacon(beacon);
        }
    }

CoreBluetooth不是一种格式。它是iOS上的一组API。使用CoreBluetooth,您可以检测多种信标格式,但有以下限制:

AltBeacon格式只能通过前台的iOS应用程序检测 Eddystone格式可以在前景和背景中检测,但在背景中检测速度比iBeacon慢。 CoreBluetooth无法检测到iBeacon格式。为此,必须使用CoreLocation。 要在核心蓝牙可检测的AltBeacon中发布,请使用以下代码:

Beacon beacon = new Beacon.Builder()
        .setId1("2f234454-cf6d-4a0f-adf2-f4911ba9ffa6")
        .setId2("1")
        .setId3("2")
        .setManufacturer(0x0118)
        .setTxPower(-59)
        .setDataFields(Arrays.asList(new Long[] {0l}))
        .build();
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);
用CoreBlutooth解析信标是很棘手的。您可能希望使用类似的工具来执行此操作


另外值得一提的是,iOS不能宣传AltBeacon或Eddystone格式。它只能宣传iBeacon和GATT服务UUID。

感谢您的快速回复。这确实帮助我从一个角度来理解这些限制。还有一件事,ios在后台做广告的方式有哪些?ios上的后台广告仅限于溢出区广告。您可以根据Overflow Area Advertision blog中建议的功能阅读更多关于这些的信息,您是否有一个示例应用程序,在以iBeacon格式扫描时扫描位掩码中的每个可能位?上述存储库中使用的格式基于GATT服务UUID,对吗?是否有任何特定于iBeacon的内容,我们可以在后台扫描并以iBeacon格式发布?