4

In the 9.2 Release Notes of Google Play services I found the following:

Nearby

This release removes the requirement that clients use the Proximity Beacon API to manage their beacons. Nearby will now return parsed BLE advertisements directly, allowing clients to use their own solution to interpret those advertisements.

That sounds to me, as if I should be able to subscribe to Nearby Messages with Strategy.BLE_ONLY and get information about BLE beacons (which includes iBeacons) in the vicinity without "owning"/registering the beacons vie Proximity Beacon API.

Do I understand that correctly? Does anyone have a helpful link to a sample or other resources that might help implementing this feature?

4

2 回答 2

1

使用使用includeIBeaconIds的 MessageFilter 订阅。

代码看起来像:

MessageFilter filter = new MessageFilter.Builder()
    .includeIBeaconIds(MY_IBEACON_PROXIMITY_UUID, null, null)
    .build();
SubscribeOptions options = new SubscribeOptions.Builder()
    .setFilter(filter)
    .setStrategy(Strategy.BLE_ONLY)
    .build();
MessageListener listener = new MessageListener() {
  @Override
  public void onFound(Message message) {
    IBeaconId beaconId = IBeaconId.from(message);
    Log.i("Test", "Saw iBeacon " + beaconId);
  }
};
Nearby.Messages.subscribe(apiClient, messageListener, options);
于 2016-08-17T08:13:46.413 回答
0

有没有人有一个有用的链接到示例或其他可能有助于实现此功能的资源?

从 Android 设备收听 iBeacon 是可能的,正如在这个SO 线程这个中所证实的那样。您可以使用AltBeacon/android-beacon-library

它允许 Android 设备像 iOS 设备一样使用信标。当一个或多个信标出现或消失时,应用程序可以请求获取通知。应用程序还可以请求以大约 1Hz 的频率从一个或多个信标获取测距更新。

不要忘记阅读有关从 Google Docs获取信标消息的信息。

这是在前台订阅时的一个片段:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ...
    mMessageListener = new MessageListener() {
        @Override
        public void onFound(Message message) {
            String messageAsString = new String(message.getContent());
            Log.d(TAG, "Found message: " + messageAsString);
        }

        @Override
        public void onLost(Message message) {
            String messageAsString = new String(message.getContent());
            Log.d(TAG, "Lost sight of message: " + messageAsString);
        }
    }
}
于 2016-08-18T03:18:00.403 回答