Piodo Piodo - 1 year ago 67
Android Question

Refresh distance to selected iBeacon device using Altbeacon library on Android

I want to display current distance computed by getDistance() function from AltBeacon library on selected beacons.

For example I have 3 beacons in range and 2 of them are saved in SavedBeacons - this is collection of beacons object. There are beacons that User has selected from

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

I would like to have displayed them(Only the selected ones) with auto 1 second update on thier current distance.

Now The output is just the beacons information and the distance saved at the time I've added it to SavedBeacons Collection. Its distance isnt updating.

Here's my class with activity to show selected beacons:

public class SelectBeacon extends Activity {

private ListView listview;
private AdapterBeaconDevices bAdapter;
private TextView noBeaconsFound;

protected void onCreate(Bundle savedInstanceState) {

this.bAdapter = new AdapterBeaconDevices(this, SavedBeacons);

listview = ((ListView) findViewById(R.id.listView2));

noBeaconsFound = (TextView) findViewById(R.id.empty2);

listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {

public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
//nothing yet


private void refresh(){

final Handler handler = new Handler();
handler.postDelayed( new Runnable() {

public void run() {

Toast.makeText(SelectBeacon.this, "test_refresh_msg",


handler.postDelayed( this, 1000 );
}, 1000 );

private void SetEmptyButtonVisiblity(final int a)
runOnUiThread(new Runnable() {
public void run() {
if (a == 0) {
} else {

protected void onDestroy() {

protected void onPause() {

protected void onResume() {

Answer Source

I've solved this problem by defining unique range containing specific ids to selected beacon

beaconManager.startRangingBeaconsInRegion(new Region("myRangingUniqueId", id1, id2, id3));

While working with multiple beacons, I scan for all beacons then just print only those whose ids are the same as the beacons in SavedList.

Maybe it will help someone.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download