Can a HTC advertise itself as a BLE Beacon?

后端 未结 3 1601
深忆病人
深忆病人 2020-12-10 09:17

Ive been doing some work around BLE and iBeacons. At present I\'m aware that you can turn your iPhone into an iBeacon but I have not come across any details of whether this

相关标签:
3条回答
  • 2020-12-10 09:52

    As long as your phone is L or 5.0 (I tried this on Nexus Player)

    To build ontop of what David wrote. Download AltBeacon make sure you check out branch android-l-apis Build your aar with ./gradlew release and include in your project.

            Beacon beacon = new Beacon.Builder()
                    .setId1("00000000-7777-5555-3333-000000000000")
                    .setId2("1")
                    .setId3("2")
                    .setManufacturer(0x004c)
                    .setTxPower(-59)
                    .setDataFields(Arrays.asList(new Long[]{0l}))
                    .build();
            mBeaconTransmitter = new BeaconTransmitter(this, new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
            mBeaconTransmitter.startAdvertising(beacon);
    

    Not sure if you would upset Apple by using 0x004c ... that is their company manufacture code. I would investigate it more if you intend production. But for engineering testing it should be ok to test around.

    I'm able to detect this beacon as iBeacon in both Gimbal app on iOS and iBeacon Locate on Android.

    0 讨论(0)
  • 2020-12-10 09:53

    Android devices have a public APIs to transmit BLE advertisements only starting with Android 5.0. You would need to install this operating system on your HTC One to do this in a regular app. I have made an app that transmits with the intellectual property-free AltBeacon standard, and put it in the Play Store here.. Source code is available here. Again, you need Android L for this to work.

    Alternatively, Android 4.4.3 also has hidden APIs that allow transmitting BLE advertisements. Building a transmitter app against 4.4.3 has three challenges:

    1. You must manually compile a special version of the Android SDK from source to unlock the hidden APIs so you can build your app.

    2. The permissions needed to transmit in 4.4.3 require system privileges,
      So you have to root your phone to install it in as special location. This makes it impractical to distribute such an app in the Play Store.

    3. A bug in 4.4.3 limits the length of advertisements to one byte less than needed to transmit a 20 byte beacon identifier and a one byte reference tx power value. This means you have to leave off that latter field making it impossible to "range" or estimate distance to the transmitter from other devices.

    0 讨论(0)
  • 2020-12-10 09:55

    This is possible on Android 5 Lollipop if your device supports it: https://code.google.com/p/android-developer-preview/issues/detail?id=1570#c52

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