Can an Android device act as an iBeacon?
Asked Answered
R

3

81

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?

Randallrandan answered 26/10, 2013 at 4:46 Comment(3)
You should break away from "IBeacon" and break it up into a general term, do some research.Mensa
@Mensa i had read this tutorial : devfright.com/ibeacons-tutorial-ios-7-clbeaconregion-clbeacon But i have confusion so ask question here. Please help me if you have any idea about this same.Randallrandan
Check this link to turn your android 5.0 phone to an iBeacon device developer.radiusnetworks.com/2014/11/18/…Ferne
L
77

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.

Labium answered 26/10, 2013 at 12:55 Comment(10)
Also this! See "BLE Peripheral Mode" -> android-developers.blogspot.com/2014/06/…Ema
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?Diacid
If you post a new question, I will answer -- not enough room to explain in comments.Labium
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?Dree
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 outLabium
Isn't the class developer.android.com/reference/android/bluetooth/le/… the answer?Meshach
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.Labium
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.Rna
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/…Labium
@Labium I have asked the question regarding support on a rooted 4.4 device at #34424979 ... thanks for your helpful answers :)Sagittarius
A
19

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

Acord answered 19/2, 2016 at 7:13 Comment(6)
Thanks for sharing. :)Randallrandan
Does this need a rooted device?Arroba
No, there is no need to root the device :))Acord
How to do this in react-native?Thingumajig
how to implement this in cordova ?Balalaika
@Acord What will be the manufacturer data for Android?Basel
H
8

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.

Histolysis answered 30/1, 2019 at 14:3 Comment(2)
Thanks for your answer, I've got it working, however only after adding an extra byte to the payload, with the tx power.Tusche
How did you determine manufacturer data? I mean what data will be there for Android?Basel

© 2022 - 2024 — McMap. All rights reserved.