javaandroidbluetooth-lowenergybeaconeddystone

Eddystone beacons are not working when use Beacons-Android library


I tried to Implements an Eddystone beacon on android device using beacon-android library https://github.com/adriancretu/beacons-android#features as follows.

public class MainActivity extends AppCompatActivity {

    EddystoneURL beacon = new EddystoneURL("www.github.com");

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Beacons.initialize(this);

        beacon.init(5, AdvertiseSettings.ADVERTISE_MODE_LOW_LATENCY,AdvertiseSettings.ADVERTISE_TX_POWER_HIGH,0,"Eddie");
        beacon.start();

        UUID uuid = beacon.getUUID();
        String name = beacon.getName();
        Log.i("Log","name is "+name);
        Log.i("Log",uuid.toString());
        String url = beacon.getURL();
        Log.i("Log",url);
        Log.i("Log","App started");
        int k = beacon.getActiveState();
        Log.i("Log","active state : "+k);
        int powerlvl = beacon.getTxPowerLevel();
        Log.i("Log","Power Lvl : "+ powerlvl);
    }


}

and I get logs as follows

2020-04-09 20:27:42.771 14922-14922/? I/Log: name is Eddie
2020-04-09 20:27:42.772 14922-14922/? I/Log: 21ac707d-2ef0-4578-aa52-f8b8020d97c3
2020-04-09 20:27:42.772 14922-14922/? I/Log: www.github.com
2020-04-09 20:27:42.772 14922-14922/? I/Log: App started
2020-04-09 20:27:42.772 14922-14922/? I/Log: active state : 0
2020-04-09 20:27:42.772 14922-14922/? I/Log: Power Lvl : 3

the problem is the emulated beacon is was not identified by beacon scanners. I really appreciate the help of yours. Thank you.


Solution

  • I realize this question is about building a transmitter with the beacons-android library, so a better answer would be to show how to make this work properly with that library.

    However, if no solution is found and the OP is open to using the Android Beacon Library (similarly named but completely different) to accomplish this, the code below will do it:

    try {
        byte[] urlBytes = UrlBeaconUrlCompressor.compress("https://www.github.com"");
        Identifier encodedUrlIdentifier = Identifier.fromBytes(urlBytes, 0, urlBytes.length, false);
        ArrayList<Identifier> identifiers = new ArrayList<Identifier>();
        identifiers.add(encodedUrlIdentifier);
        beacon = new Beacon.Builder()
                .setIdentifiers(identifiers)
                .setTxPower(-59)
                .build();
        BeaconParser beaconParser = new BeaconParser()
                .setBeaconLayout(BeaconParser.EDDYSTONE_URL_LAYOUT);
        BeaconTransmitter beaconTransmitter = new BeaconTransmitter(getApplicationContext(), 
                  beaconParser);
        beaconTransmitter.startAdvertising(beacon);
    } catch (MalformedURLException e) {
        Log.d(TAG, "That URL cannot be parsed");
    }
    

    Full Disclosure: I am the lead developer on the Android Beacon Library open source project.