0

I need to emulate beacon. I use devices

  • Android 6.0 (LG, Nexus 5)
  • Android 9.0 (Honor 10)

In my app/build.gradle:

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

In my activity:

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);
        }
    }

But isSupported is always false. And as result not execute:

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

How I can fix this? Is it possible to emulate beacons by this lib or maybe has another approach?

Alexei
  • 14,350
  • 37
  • 121
  • 240

1 Answers1

1

Unfortunately, there is no way to fix this with the Android operating system installed on these phones. The operating system itself blocks transmitting BLE advertisements if isMultipleAdvertisementSupported returns false. See here for the explanation about the Nexus 5.

In theory you can root your Nexus 5 and install a different ROM image that does not block BLE advertising. I know from my own experience that the Android L beta 1 build for the Nexus 5 did allow advertising. That ROM image is no longer available from Google, but you may be able to find another installable ROM for the Nexus 5 that does not block this.

As for Huawei Honor devices, many do not support advertising but some others do. Here's a slightly dated table that shows the ones known to support advertising.

davidgyoung
  • 63,876
  • 14
  • 121
  • 204
  • To do beacon transmission I must use device from this table? Is it possible to do this by Android emulator? – Alexei Oct 21 '19 at 21:16
  • 1
    Yes, you must use a device in that table, although newer devices not mentioned in the table may also work. Android emulators do not emulate Bluetooth, so you cannot use them as transmitters. – davidgyoung Oct 22 '19 at 01:23