Android Question BLE Peripheral as Ibeacon


Active Member
Licensed User
Longtime User
I found the sequence to set as Ibeacon with BLE Peripheral library but I could not succeed to create the map

'protected void setAdvertiseData() {
'     AdvertiseData.Builder mBuilder = new AdvertiseData.Builder()
'     ByteBuffer mManufacturerData = ByteBuffer.allocate(23);
'     byte[] uuid = getIdAsByte(UUID.fromString("0CF052C297CA407C84F8B62AAC4E9020"));
'     mManufacturerData.put(0, (byte)0x02);
'     mManufacturerData.put(1, (byte)0x15);
'     For (int i=2; i<=17; i++) {
'       mManufacturerData.put(i, uuid[i-2]); // adding the UUID
'     }
'     mManufacturerData.put(18, (byte)0x00); // first byte of Major
'     mManufacturerData.put(19, (byte)0x09); // second byte of Major
'     mManufacturerData.put(20, (byte)0x00); // first minor
'     mManufacturerData.put(21, (byte)0x06); // second minor
'     mManufacturerData.put(22, (byte)0xB5); // txPower
'     mBuilder.addManufacturerData(76, mManufacturerData.array());
'     mAdvertiseData =;

Private Sub Manager_StateChanged (State As Int)
    If State <> manager.STATE_POWERED_ON Then
        ToastMessageShow("Please enable Bluetooth", True)
        NotAvailable = True
        peripheral.Initialize("peripheral", manager)
        'peripheral.ManufacturerData = CreateMap(123: "this is my data".GetBytes("utf8"))
       ' peripheral.ManufacturerData = CreateMap(123: "this is my data".GetBytes("utf8"), 124: Array As Byte(1, 2, 3, 4))
        'peripheral.ManufacturerData = CreateMap(0x0700: "abc".GetBytes("utf8"))
        Dim xManuf () As Byte
        xManuf =  Array As Byte (2, 21,48,14,45,65,48,14,45,65,48,14,45,65,48,14,45,65 ,12,35,12,36,111)
        peripheral.ManufacturerData = CreateMap(22: xManuf )
        If peripheral.IsPeripheralSupported = False Then
            ToastMessageShow("Peripheral mode not supported.", True)
            NotAvailable = True
             peripheral.Start2("B4APeripheral", CreateAdvertiseSettings)

'            peripheral.Start("B4APeripheral")
            Wait For Peripheral_Start (Success As Boolean)
            Log("Peripheral started successfully? " & Success)
        End If
    End If
End Sub

The comment code is from a site that explain the sequency



B4X founder
Staff member
Licensed User
Longtime User
Porting this code:

Dim bb As B4XBytesBuilder 'B4XCollections
bb.Append(Array As Byte(0x02, 0x15))
Dim bc As ByteConverter
bb.Append(Array As Byte(0, 9, 0, 6, 0xb5))
Dim b() As Byte = bb.ToArray
peripheral.ManufacturerData = CreateMap(76: b )
Upvote 0


Active Member
Licensed User
Longtime User
Doesn´t work.

The addManufacturerData expect an "int" and an "array" ( addManufacturerData( int , array) ).

I found this link

I suggest to create a command
peripheral.Start3("Beacon_Name", CreateAdvertiseSettings, CreateAdvertiseData)

Private Sub CreateAdvertiseData As Object
    Dim builder As JavaObject
    builder.InitializeNewInstance("android.bluetooth.le.AdvertiseData.Builder", Null)
    builder.RunMethod("setIncludeTxPowerLevel", Array(False))
    builder.RunMethod("setIncludeDeviceName", Array(False))
    builder.RunMethod("addManufacturerData", Array (0x4c, b) )
    Return builder.RunMethod("build", Null)
End Sub

So we can manage all the parameters from peripheral configuration

This application can simulate and read beacon.

Using this apk to read the ibeacon when the manufacterer is not set I can see the bluetooth conectio ( not as ibeacon ) and when the manufacturer is set I can´t see the bluetooth at all
Last edited:
Upvote 0


Active Member
Licensed User
Longtime User
Some tests

First: I run the software Beacon Simulator FIG 1 and I create a IBeacon UUID 6bd58 ...." that I could read in the same software with the mode scan in a Moto G6 Fig 2 and it recognize as IBeacon

Second: I run the B4a software in a Moto X without the command "peripheral.ManufacturerData = CreateMap(76: b )" and in Moto G6 I could read the bluetooth connection but as a regular Bluetooth Fig 3 ( I can see the name "SVO_Beacon" ) in the list.

Three: I run the B4A software in a Moto X with the command "peripheral.ManufacturerData = CreateMap(76: b )" and in Moto G6 I couldn´t find any Bluetooth connection FIG 4.

I send in attach the zip from the project and the link to apk that I used for simulate an IBeacon and to scan is at topic #6


    10.7 KB · Views: 324
  • Fig2.png
    122.6 KB · Views: 294
  • Fig3.png
    184.9 KB · Views: 288
  • Fig4.png
    169.9 KB · Views: 284
  • Fig1.png
    447.8 KB · Views: 304
Upvote 0