Can an Android device act as an iBeacon?

49,163

Solution 1

YES This is possible on Android 5+, and you can find open-source code for transmitting as a beacon in the Android Beacon Library. There is also a full-featured version of a beacon transmitter in the Beacon Scope app in the Google Play Store.

Here's an example of transmitting iBeacon with the Android Beacon Library:

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

You can also transmit as a beacon on rooted Android 4.4.3 devices, but it requires an app installed with system privileges.

Android 4.3 devices with BluetoothLE can see iBeacons but not act as iBeacons, because Android 4.3 does not support peripheral mode. Samsung Android devices contain a separate proprietary SDK but it also does not allow devices to act as iBeacons. See: Make Samsung Android device advertise as an iBeacon) iOS devices, however, can act as iBeacons.

Normally, iBeacon technologies are not intended for phones to see other phones. But you could do what you suggest on iOS by making a custom app that makes phones act as an iBeacon and look for other iBeacons around them. This would allow anybody with the app to see others with the same app nearby. All phones would need Bluetooth turned on.

To answer your second question, yes, a mobile device, both Android or iOS, must have an app installed to take advantage of iBeacons. Neither operating system currently does anything when it sees an iBeacon unless an app is installed that is specifically programmed to do something. So customers who arrive in a store must have an app already installed or they cannot interact with iBeacons.

Solution 2

Yes, Android devices can act as iBeacon. I achieve this using android 5.X and AltBeacon library. AltBeacon library from Radius Networks provide classes to build android as beacon emitter and receptor as well. Here is some piece of code that will work for android as iBeacon :

 Beacon beacon = new Beacon.Builder()
        .setId1("2f234454-cf6d-4a0f-adf2-f4911ba9ffa6") // UUID for beacon
        .setId2("1") // Major for beacon
        .setId3("5") // Minor for beacon
        .setManufacturer(0x004C) // Radius Networks.0x0118  Change this for other beacon layouts//0x004C for iPhone
        .setTxPower(-56) // Power in dB
        .setDataFields(Arrays.asList(new Long[] {0l})) // Remove this for beacon layouts without d: fields
        .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, new AdvertiseCallback() {

            @Override
            public void onStartFailure(int errorCode) {
                Log.e(TAG, "Advertisement start failed with code: "+errorCode);
            }

            @Override
            public void onStartSuccess(AdvertiseSettings settingsInEffect) {
                Log.i(TAG, "Advertisement start succeeded.");
            }
        });

Hope it will helpful for user searching for android as iBeacon. jj

Solution 3

Pure Android SDK. Zero 3rd party code - good for Open Source Due Diligence

byte[] payload = {(byte)0x02, (byte)0x15, // this makes it a iBeacon
            (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, // uuid
            (byte)0x00, (byte)0x00,  // Major
            (byte)0x00, (byte)0x00}; // Minor


    AdvertiseData.Builder dataBuilder = new AdvertiseData.Builder();
    dataBuilder.addManufacturerData(0x004C, payload); // 0x004c is for Apple inc.
    AdvertiseSettings.Builder settingsBuilder = new AdvertiseSettings.Builder();

    settingsBuilder.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_LOW_LATENCY);
    settingsBuilder.setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_HIGH);
    settingsBuilder.setConnectable(false);

    mAdvertiser.startAdvertising(settingsBuilder.build(), dataBuilder.build(), this);

Put your UUID Minor Mayor in those places in payload, but leave the first two bytes as it is.

Share:
49,163

Related videos on Youtube

Hardik Joshi
Author by

Hardik Joshi

Right now i am working as an Android Application Developer having 8+ years of experience. Contact Me: Mail: [email protected] Skype: hardik.joshi841 Proud to be INDIAN Some owsome Apps Join Me : http://androiddevelopmentworld.blogspot.in/

Updated on July 05, 2022

Comments

  • Hardik Joshi
    Hardik Joshi almost 2 years

    Can an Android device act as an iBeacon and figure out when other Android devices come in its range? Do those other Android devices need to have Bluetooth turned on?

    If a customer comes into my shop and he doesn't have my app installed on his device, can iBeacon work, or must he install the app first? There are so many customers are visiting our shop daily, but if they don't have my app installed, does the iBeacon concept work?

  • Alexis
    Alexis almost 10 years
    Also this! See "BLE Peripheral Mode" -> android-developers.blogspot.com/2014/06/…
  • Raiv
    Raiv over 9 years
    You can also transmit as a beacon on rooted Android 4.4.3 devices, but it requires an app installed with system privileges. How can I do that?
  • davidgyoung
    davidgyoung over 9 years
    If you post a new question, I will answer -- not enough room to explain in comments.
  • petersaints
    petersaints over 9 years
    Nice and informative answer. But I have a doubt regarding this sentence: "Doing this on Android would currently only be possible with Samsung devices." Just a little bit above you say that the Samsung SDK does not allow devices to act like iBeacons (and link to a question that has the same answer). If that's so... how can Samsung devices act like iBeacons if the Android SDK doesn't allow it and the Samsung SDK is also incapable of such feature?
  • davidgyoung
    davidgyoung over 9 years
    You are correct, it is not possible on Samsung's BLE SDK. That sentence was left over from an earlier edit of the answer before I did a proof that it was not possible with the Samsung SDK. I have struck it out
  • Marian Paździoch
    Marian Paździoch about 9 years
  • davidgyoung
    davidgyoung about 9 years
    Yes, that is the class to use on Android 5.0+. See the link from the UPDATE in the answer above. When the answer was originally written, Android 5.0 was not out yet, which is the reason for the update.
  • Nick
    Nick over 8 years
    This answer does not discuss chipsets. Even after installing 5.0.1 on my galaxy S4, it will not act as a peripheral. My understanding is you need a chipset that supports it.
  • davidgyoung
    davidgyoung over 8 years
    That is an important clarification, yes. Not only does transmission on Android 5.x+ require chipset support, but it also requires support in the ROM. Nexus 5 devices, for example, have chipset support, but Google disabled support in the official ROM. I have compiled a list of devices known to support and not support transmission here: altbeacon.github.io/android-beacon-library/…
  • Martin
    Martin over 8 years
    @davidgyoung I have asked the question regarding support on a rooted 4.4 device at stackoverflow.com/questions/34424479/… ... thanks for your helpful answers :)
  • Hardik Joshi
    Hardik Joshi about 8 years
    Thanks for sharing. :)
  • Amitabh
    Amitabh almost 8 years
    Does this need a rooted device?
  • Yogesh
    Yogesh almost 8 years
    No, there is no need to root the device :))
  • user43286
    user43286 about 7 years
    How to do this in react-native?
  • Atul Verma
    Atul Verma almost 7 years
    how to implement this in cordova ?
  • José Pereda
    José Pereda about 4 years
    Thanks for your answer, I've got it working, however only after adding an extra byte to the payload, with the tx power.
  • Sumit Shukla
    Sumit Shukla over 2 years
    How did you determine manufacturer data? I mean what data will be there for Android?
  • Sumit Shukla
    Sumit Shukla over 2 years
    @Yogesh What will be the manufacturer data for Android?