下午好。我正在开发一个Android应用程序,并且正在尝试将一个估算信标与该应用程序集成。问题是我希望能够发现更改设备的UUID,次要,主要的特定设备。

要发现和排列我正在使用的信标:

    beaconManager.startRanging(region);

            beaconManager.setRangingListener(new BeaconManager.RangingListener() {
                @Override
                public void onBeaconsDiscovered(Region region, List<Beacon> list) {

                    if (!list.isEmpty()) {

                        for(Beacon b : list){

                            if (b.getMacAddress().equals(macaddress)){

 %%Now that i have the Beacon b I would like to change it's UUID, major and minor.
                            }
                        }
                    }
                }
            });


有人可以帮我吗?我知道,要更改UUID,我需要连接到estimote云,但是我不太了解如何使用(他们网站上的示例使用了BeaconConnection,但已弃用)。

最佳答案

我使用了这个方法,我在Estimote andriod sdk上发现了它,但Estimote不赞成使用它,但是通过在android studio中使用适当的api设置,可以正常工作。

我还找不到替代解决方案,但是如果找到,我将更新答案。

private void editBeacon(final Beacon beacon, UUID newUuid, int newMinor, int newMajor) {
    connection = new BeaconConnection(this, beacon, new BeaconConnection.ConnectionCallback() {
        @Override
        public void onAuthorized(BeaconInfo beaconInfo) {

        }

        @Override
        public void onConnected(BeaconInfo beaconInfo) {
            Log.d(TAG, "Authenticated to beacon. Info: " + beaconInfo);
            Log.d(TAG, "Advertising internal: " + connection.advertisingIntervalMillis().get());
            Log.d(TAG, "Broadcasting transmitPower: " + connection.broadcastingPower().get());
        }

        @Override
        public void onAuthenticationError(EstimoteDeviceException exception) {
            Log.d(TAG, "Authentication Error: " + exception);
        }

        @Override
        public void onDisconnected() {
            Log.d(TAG, "Disconnected");
        }
    });

    connection.authenticate();

    // Interact with beacon.

    // You can update beacon's properties in following way:
    connection.edit()
            .set(connection.proximityUuid(), newUuid)
            .set(connection.major(), newMajor)
            .set(connection.minor(), newMinor)
            .commit(new BeaconConnection.WriteCallback() {
                @Override
                public void onSuccess() {
                }

                @Override
                public void onError(EstimoteDeviceException exception) {
                }
            });

    // Do not forget to close connection.
    connection.close();
}

08-18 05:05
查看更多