Can an Android device act as an iBeacon?

前端 未结 3 1613
耶瑟儿~
耶瑟儿~ 2020-11-29 16:00

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?

相关标签:
3条回答
  • 2020-11-29 16:45

    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.

    0 讨论(0)
  • 2020-11-29 16:45

    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

    0 讨论(0)
  • 2020-11-29 16:49

    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.

    0 讨论(0)
提交回复
热议问题