![](/img/trans.png)
[英]How to get the AltBeacon library's BootstrapRegion to recognize the iBeacon layout?
[英]Refresh distance to selected iBeacon device using Altbeacon library on Android
我想在選定的信標上顯示從AltBeacon庫中的getDistance()函數計算出的當前距離。
例如,我在范圍內有3個信標,其中2個保存在SavedBeacons中-這是信標對象的集合。 用戶已從public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region)
函數中選擇了一些public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region)
。
我想以當前距離自動更新1秒顯示它們(僅選中的對象)。
現在,輸出只是信標信息,並且是我將其添加到SavedBeacons集合時保存的距離。 它的距離沒有更新。
這是我的班級,活動顯示所選信標:
public class SelectBeacon extends Activity {
private ListView listview;
private AdapterBeaconDevices bAdapter;
private TextView noBeaconsFound;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_select_beacon);
this.bAdapter = new AdapterBeaconDevices(this, SavedBeacons);
listview = ((ListView) findViewById(R.id.listView2));
listview.setAdapter(bAdapter);
noBeaconsFound = (TextView) findViewById(R.id.empty2);
SetEmptyButtonVisiblity(SavedBeacons.size());
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
//nothing yet
}
});
refresh();
}
private void refresh(){
final Handler handler = new Handler();
handler.postDelayed( new Runnable() {
@Override
public void run() {
Toast.makeText(SelectBeacon.this, "test_refresh_msg",
Toast.LENGTH_LONG).show();
bAdapter.notifyDataSetChanged();
handler.postDelayed( this, 1000 );
}
}, 1000 );
}
private void SetEmptyButtonVisiblity(final int a)
{
runOnUiThread(new Runnable() {
@Override
public void run() {
if (a == 0) {
noBeaconsFound.setVisibility(View.VISIBLE);
} else {
noBeaconsFound.setVisibility(View.GONE);
}
}
});
}
@Override
protected void onDestroy() {
super.onDestroy();
}
@Override
protected void onPause() {
super.onPause();
}
@Override
protected void onResume() {
super.onResume();
}
}
我已經通過定義包含選定信標的特定ID的唯一范圍來解決此問題
beaconManager.startRangingBeaconsInRegion(new Region("myRangingUniqueId", id1, id2, id3));
當使用多個信標時,我掃描所有信標,然后僅打印其ID與SavedList中的信標相同的信標。
也許會幫助某人。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.