简体   繁体   English

HTC可以将自己宣传为BLE Beacon吗?

[英]Can a HTC advertise itself as a BLE Beacon?

Ive been doing some work around BLE and iBeacons. 我一直在做一些关于BLE和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 is possible with an Android phone - specifically a HTC One as that the one I've got ;) 目前我知道你可以将你的iPhone变成iBeacon但是我还没有看到任何有关Android手机是否可行的细节 - 特别是HTC One就像我得到的那样;)

Any advice, details or web links on this matter would be appreciated, 有关此事的任何建议,细节或网站链接将不胜感激,

Thanks, 谢谢,

Steve 史蒂夫

Android devices have a public APIs to transmit BLE advertisements only starting with Android 5.0. Android设备有一个公共API,只能从Android 5.0开始传输BLE广告。 You would need to install this operating system on your HTC One to do this in a regular app. 您需要在HTC One上安装此操作系统才能在常规应用中执行此操作。 I have made an app that transmits with the intellectual property-free AltBeacon standard, and put it in the Play Store here. 我已经制作了一个使用无知识产权的AltBeacon标准传输的应用程序,并将其放在Play商店中。 . Source code is available here. 源代码可在此处获得。 Again, you need Android L for this to work. 同样,你需要Android L才能工作。

Alternatively, Android 4.4.3 also has hidden APIs that allow transmitting BLE advertisements. 或者,Android 4.4.3也有隐藏的 API,允许传输BLE广告。 Building a transmitter app against 4.4.3 has three challenges: 针对4.4.3构建发射器应用程序有三个挑战:

  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. 您必须从源手动编译特殊版本的Android SDK以解锁隐藏的API,以便您可以构建您的应用程序。

  2. The permissions needed to transmit in 4.4.3 require system privileges, 在4.4.3中传输所需的权限需要系统权限,
    So you have to root your phone to install it in as special location. 因此,您必须将手机设为root用户才能将其安装在特殊位置。 This makes it impractical to distribute such an app in the Play Store. 这使得在Play商店中分发此类应用程序变得不切实际。

  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. 4.4.3中的错误将广告的长度限制为比发送20字节信标标识符单字节参考tx功率值所需的字节少一个字节。 This means you have to leave off that latter field making it impossible to "range" or estimate distance to the transmitter from other devices. 这意味着你不得不放弃后一个场,这使得无法“范围”或估计从其他设备到发射机的距离。

As long as your phone is L or 5.0 (I tried this on Nexus Player) 只要您的手机是L或5.0(我在Nexus播放器上试过这个)

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. 下载AltBeacon确保你检查分支机构android-l-apis使用./gradlew版本构建你的aar并包含在你的项目中。

        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. 不确定你是否会使用0x004c来扰乱Apple ...这是他们公司的制造代码。 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. 我能够在iOS上的Gimbal应用程序和Android上的iBeacon Locate中将此信标检测为iBeacon。

如果您的设备支持Android 5 Lollipop,则可以使用此功能: https//code.google.com/p/android-developer-preview/issues/detail?id = 1570#c52

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM