0

My app has to broadcast via Bluetooth an iBeacon message. The iBeacon message should be fixed in a particular UUID, Major and Minor.

How can it be done without using any 3rd party applications? (I'm okay with libraries, I just don't want the user to need another app to use this app. I prefer this app to be self-dependent when being used).

EDIT : I've built it with only google ble docs and any other libraries haven't been used. Though, I'm open to implement any suggestions that make it work.

C Forge
  • 215
  • 1
  • 8

1 Answers1

1

The easiest way to do this is to use the Android Beacon Library which is totally free and open source.

  1. Add this to your build.gradle dependencies:

     dependencies {
        implementation 'org.altbeacon:android-beacon-library:2+'
     }
    
  2. Paste this code to start your transmitter:

     Beacon beacon = new Beacon.Builder()
        .setId1("2f234454-cf6d-4a0f-adf2-f4911ba9ffa6")
        .setId2("1")
        .setId3("2")
        .setManufacturer(0x004c)
        .setTxPower(-59)
        .build();
     BeaconParser beaconParser = new BeaconParser()
        .setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24");
     BeaconTransmitter beaconTransmitter = new 
     BeaconTransmitter(getApplicationContext(), beaconParser); 
     beaconTransmitter.startAdvertising(beacon);
    

If you really want to not compile against a third-party library, you are welcome to copy the source code for the BeaconTransmitter, but that's harder to do:

https://github.com/AltBeacon/android-beacon-library/blob/master/src/main/java/org/altbeacon/beacon/BeaconTransmitter.java

davidgyoung
  • 63,876
  • 14
  • 121
  • 204
  • thank you Mr. Young, I did exactly this from Morrison Chang's suggestion above. Almost the entirety of my project is built from your answers from different posts all over SO – C Forge Nov 28 '18 at 00:00