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

时间:2015-04-10 15:09:45

标签: android ibeacon ibeacon-android altbeacon android-ibeacon

所以基本上想要更新作为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);

1 个答案:

答案 0 :(得分:1)

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

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