在读取 Beacon 的距离时更新布局

update the layout while reading distances from Beacon

所以基本上想更新 ImageView 的布局,但为此需要停止信标的测距,并使用 beaconManager.unbind(上下文),然后再次更新图像绑定 beaconManager.bind (context) 问题是这个上下文需要 "org.altbeacon.beacon.BeaconConsumer" 如何创建那个类型的上下文或者不是这样但是需要调用 beaconManager 的另一个方法来停止 rangin 并重新开始?

public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {

                /*
                if (beacons.size() > 0) {
                    Log.i(TAG, "The first beacon I see is about " + beacons.iterator().next().getDistance() + " meters away.");
                }
                */



                for(Beacon beacon: beacons){

                    double distancia = beacon.getDistance();

                    if(false) {
                        int rssi = beacon.getRssi();
                        int power = beacon.getTxPower();
                        //double distancia = beacon.getDistance();

                        distancias.add(beacon.getDistance());
                        Log.i(TAG, "Beacon detected with id1: " + beacon.getId1() + " id2:" + beacon.getId2() + " id3: " + beacon.getId3() + " distance: " + beacon.getDistance());
                        Log.i(TAG, "rss value->" + rssi + "  power->" + power);
                    }


                    if(distancia <= 1.0){
                        Log.i(TAG,"esta a 1m de alcance");



                        /*
                        Bitmap bmp = BitmapFactory.decodeResource(context.getResources(),R.drawable.image5m);
                        Radar.setImageBitmap(bmp);
                        */


                    }else if(distancia <= 2.0){/
                        Log.i(TAG,"esta a 2m de alcance");

                        //org.altbeacon.beacon.BeaconConsumer
                        //beaconManager.setAndroidLScanningDisabled(true);//setMonitorNotifier
                        beaconManager.unbind(ex);

                        Bitmap bmp = BitmapFactory.decodeResource(context.getResources(), R.drawable.image10m);
                        Radar.setImageBitmap(bmp);

您无需停止信标扫描即可更新 UI。您只需要在 UI 线程上执行 UI 更改。像这样:

runOnUiThread(new Runnable() {
    public void run() {
        Bitmap bmp = BitmapFactory.decodeResource(context.getResources(), R.drawable.image10m);
        Radar.setImageBitmap(bmp);
    }
});