Gimbal "BeaconSighting" 侦听器工作不稳定
Gimbal "BeaconSighting" listener working erratically
我正在尝试在 Android 中获取 Gimbal 信标距离变化 运行 时间。我能够连接到我的信标,同样反映在 android 应用程序中。
但我无法在应用程序中获得更改后的 RSSI。下面是我的代码。
private PlaceManager placeManager;
private PlaceEventListener placeEventListener;
private ArrayAdapter<String> listAdapter;
private ListView listView;
private BeaconManager bm;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1);
listView = (ListView) findViewById(R.id.list);
listView.setAdapter(listAdapter);
listAdapter.add("Setting API Key");
listAdapter.notifyDataSetChanged();
Gimbal.setApiKey(this.getApplication(), "my key");
bm = new BeaconManager();
bm.addListener(new BeaconEventListener() {
@Override
public void onBeaconSighting(BeaconSighting beaconSighting) {
super.onBeaconSighting(beaconSighting);
Log.d("beacon1", beaconSighting.getBeacon().toString());
Log.d("beacon2", String.format("", beaconSighting.getRSSI()));
}
});
bm.startListening();
placeEventListener = new PlaceEventListener() {
@Override
public void onVisitStart(Visit visit) {
super.onVisitStart(visit);
listAdapter.add(String.format("Start Visit for %s", visit.getPlace().getName()));
listAdapter.notifyDataSetChanged();
Log.d("1", String.valueOf(visit.getArrivalTimeInMillis()));
Log.d("2", String.valueOf(visit.getDepartureTimeInMillis()));
Log.d("3", String.valueOf(visit.getPlace()));
Log.d("4", String.valueOf(visit.getDwellTimeInMillis()));
/*BeaconSighting demo = new BeaconSighting();
Beacon beac = demo.getBeacon();
Log.d("", beac.getUuid());*/
}
@Override
public void onVisitEnd(Visit visit) {
super.onVisitEnd(visit);
listAdapter.add(String.format("End Visit for %s", visit.getPlace().getName()));
listAdapter.notifyDataSetChanged();
Log.d("ending","ending");
}
};
placeManager = PlaceManager.getInstance();
placeManager.addListener(placeEventListener);
placeManager.startMonitoring();
CommunicationManager.getInstance().startReceivingCommunications();
下面是我的日志输出。
11-24 00:18:49.128 9801-9801/com.gimbal.hello_gimbal_android D/1: 1448353129095
11-24 00:18:49.128 9801-9801/com.gimbal.hello_gimbal_android D/2: 1448353076508
11-24 00:18:49.128 9801-9801/com.gimbal.hello_gimbal_android D/3: Place [identifier=D4786F227DA24C56D46884FD8A33F97E, name=abc, attributes=com.gimbal.android.a.a@123]
11-24 00:18:49.128 9801-9801/com.gimbal.hello_gimbal_android D/4: -52587
11-24 00:18:49.208 9801-9801/com.gimbal.hello_gimbal_android D/1: 1448353129095
11-24 00:18:49.208 9801-9801/com.gimbal.hello_gimbal_android D/2: 1448353076508
11-24 00:18:49.208 9801-9801/com.gimbal.hello_gimbal_android D/3: Place [identifier=6D63654565EA48D38D2D1F81E1D558F4, name=xyz, attributes=com.gimbal.android.a.a@456]
11-24 00:18:49.208 9801-9801/com.gimbal.hello_gimbal_android D/4: -52587
11-24 00:18:49.226 9801-9801/com.gimbal.hello_gimbal_android D/1: 1448353129095
11-24 00:18:49.226 9801-9801/com.gimbal.hello_gimbal_android D/2: 1448353076508
11-24 00:18:49.226 9801-9801/com.gimbal.hello_gimbal_android D/3: Place [identifier=A6E32B4B5FBF5849F7ED78FBF02D701, name=lmn, attributes=null]
11-24 00:18:49.226 9801-9801/com.gimbal.hello_gimbal_android D/4: -52587
11-24 01:33:39.383 21329-21329/com.gimbal.hello_gimbal_android D/beacon1: Beacon [identifier=uid123, name=abc, iconURL=null, batteryLevel=HIGH, temperature=74]
11-24 01:33:39.383 21329-21329/com.gimbal.hello_gimbal_android D/beacon2: -62
问题就出在这里
打印 "beacon1" 和 "beacon2" randomly/erratically。 我无法理解为什么“BeaconEventListener" 有这样的行为。大多数时候它根本没有打印出来。因此,我没有路障,因为我在移动时无法获得手机和信标之间的距离。
编辑
能够提取更多错误日志。在 logcat 输出中添加了最后两行。
感谢任何帮助。
Gimbal 团队几乎解决了这个问题,所以遇到这个问题的人将来也可以得到帮助。
在我的 OP 中,您可以看到下面是我的代码的原始部分。
bm = new BeaconManager();
bm.addListener(new BeaconEventListener() {
@Override
public void onBeaconSighting(BeaconSighting beaconSighting) {
super.onBeaconSighting(beaconSighting);
Log.d("beacon1", beaconSighting.getBeacon().toString());
Log.d("beacon2", String.format("", beaconSighting.getRSSI()));
}
});
bm.startListening();
现在我们还要在 PlaceEventListener()
中添加 onBeaconSighting()
。所以代码的新部分将如下所示。
placeEventListener = new PlaceEventListener() {
@Override
public void onVisitStart(Visit visit) {
super.onVisitStart(visit);
//do anything
}
@Override
public void onVisitEnd(Visit visit) {
super.onVisitEnd(visit);
//do anything
}
public void onBeaconSighting(BeaconSighting sighting, List<Visit> visits) {
// This will be invoked when a beacon assigned to a place within a current visit is sighted.
}
}
我们添加一个重复的或者更确切地说另一个监听器的原因由 Gimbal 团队回复如下。
Me : Can you inform me as why adding a duplicate listener made the code work ? As this listener is already handled in BeaconManger, it should have worked.
Gimbal Team : onBeaconSighting in PlaceManager will will be invoked when a beacon assigned to a place within a current visit is sighted.
onBeaconSighting in BeaconManager will be invoked when a beacon is sighted.
我想我已经很清楚问题出在哪里以及如何解决了。希望对你也有帮助。
干杯。
我正在尝试在 Android 中获取 Gimbal 信标距离变化 运行 时间。我能够连接到我的信标,同样反映在 android 应用程序中。
但我无法在应用程序中获得更改后的 RSSI。下面是我的代码。
private PlaceManager placeManager;
private PlaceEventListener placeEventListener;
private ArrayAdapter<String> listAdapter;
private ListView listView;
private BeaconManager bm;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1);
listView = (ListView) findViewById(R.id.list);
listView.setAdapter(listAdapter);
listAdapter.add("Setting API Key");
listAdapter.notifyDataSetChanged();
Gimbal.setApiKey(this.getApplication(), "my key");
bm = new BeaconManager();
bm.addListener(new BeaconEventListener() {
@Override
public void onBeaconSighting(BeaconSighting beaconSighting) {
super.onBeaconSighting(beaconSighting);
Log.d("beacon1", beaconSighting.getBeacon().toString());
Log.d("beacon2", String.format("", beaconSighting.getRSSI()));
}
});
bm.startListening();
placeEventListener = new PlaceEventListener() {
@Override
public void onVisitStart(Visit visit) {
super.onVisitStart(visit);
listAdapter.add(String.format("Start Visit for %s", visit.getPlace().getName()));
listAdapter.notifyDataSetChanged();
Log.d("1", String.valueOf(visit.getArrivalTimeInMillis()));
Log.d("2", String.valueOf(visit.getDepartureTimeInMillis()));
Log.d("3", String.valueOf(visit.getPlace()));
Log.d("4", String.valueOf(visit.getDwellTimeInMillis()));
/*BeaconSighting demo = new BeaconSighting();
Beacon beac = demo.getBeacon();
Log.d("", beac.getUuid());*/
}
@Override
public void onVisitEnd(Visit visit) {
super.onVisitEnd(visit);
listAdapter.add(String.format("End Visit for %s", visit.getPlace().getName()));
listAdapter.notifyDataSetChanged();
Log.d("ending","ending");
}
};
placeManager = PlaceManager.getInstance();
placeManager.addListener(placeEventListener);
placeManager.startMonitoring();
CommunicationManager.getInstance().startReceivingCommunications();
下面是我的日志输出。
11-24 00:18:49.128 9801-9801/com.gimbal.hello_gimbal_android D/1: 1448353129095
11-24 00:18:49.128 9801-9801/com.gimbal.hello_gimbal_android D/2: 1448353076508
11-24 00:18:49.128 9801-9801/com.gimbal.hello_gimbal_android D/3: Place [identifier=D4786F227DA24C56D46884FD8A33F97E, name=abc, attributes=com.gimbal.android.a.a@123]
11-24 00:18:49.128 9801-9801/com.gimbal.hello_gimbal_android D/4: -52587
11-24 00:18:49.208 9801-9801/com.gimbal.hello_gimbal_android D/1: 1448353129095
11-24 00:18:49.208 9801-9801/com.gimbal.hello_gimbal_android D/2: 1448353076508
11-24 00:18:49.208 9801-9801/com.gimbal.hello_gimbal_android D/3: Place [identifier=6D63654565EA48D38D2D1F81E1D558F4, name=xyz, attributes=com.gimbal.android.a.a@456]
11-24 00:18:49.208 9801-9801/com.gimbal.hello_gimbal_android D/4: -52587
11-24 00:18:49.226 9801-9801/com.gimbal.hello_gimbal_android D/1: 1448353129095
11-24 00:18:49.226 9801-9801/com.gimbal.hello_gimbal_android D/2: 1448353076508
11-24 00:18:49.226 9801-9801/com.gimbal.hello_gimbal_android D/3: Place [identifier=A6E32B4B5FBF5849F7ED78FBF02D701, name=lmn, attributes=null]
11-24 00:18:49.226 9801-9801/com.gimbal.hello_gimbal_android D/4: -52587
11-24 01:33:39.383 21329-21329/com.gimbal.hello_gimbal_android D/beacon1: Beacon [identifier=uid123, name=abc, iconURL=null, batteryLevel=HIGH, temperature=74]
11-24 01:33:39.383 21329-21329/com.gimbal.hello_gimbal_android D/beacon2: -62
问题就出在这里
打印 "beacon1" 和 "beacon2" randomly/erratically。 我无法理解为什么“BeaconEventListener" 有这样的行为。大多数时候它根本没有打印出来。因此,我没有路障,因为我在移动时无法获得手机和信标之间的距离。
编辑
能够提取更多错误日志。在 logcat 输出中添加了最后两行。
感谢任何帮助。
Gimbal 团队几乎解决了这个问题,所以遇到这个问题的人将来也可以得到帮助。
在我的 OP 中,您可以看到下面是我的代码的原始部分。
bm = new BeaconManager();
bm.addListener(new BeaconEventListener() {
@Override
public void onBeaconSighting(BeaconSighting beaconSighting) {
super.onBeaconSighting(beaconSighting);
Log.d("beacon1", beaconSighting.getBeacon().toString());
Log.d("beacon2", String.format("", beaconSighting.getRSSI()));
}
});
bm.startListening();
现在我们还要在 PlaceEventListener()
中添加 onBeaconSighting()
。所以代码的新部分将如下所示。
placeEventListener = new PlaceEventListener() {
@Override
public void onVisitStart(Visit visit) {
super.onVisitStart(visit);
//do anything
}
@Override
public void onVisitEnd(Visit visit) {
super.onVisitEnd(visit);
//do anything
}
public void onBeaconSighting(BeaconSighting sighting, List<Visit> visits) {
// This will be invoked when a beacon assigned to a place within a current visit is sighted.
}
}
我们添加一个重复的或者更确切地说另一个监听器的原因由 Gimbal 团队回复如下。
Me : Can you inform me as why adding a duplicate listener made the code work ? As this listener is already handled in BeaconManger, it should have worked.
Gimbal Team : onBeaconSighting in PlaceManager will will be invoked when a beacon assigned to a place within a current visit is sighted. onBeaconSighting in BeaconManager will be invoked when a beacon is sighted.
我想我已经很清楚问题出在哪里以及如何解决了。希望对你也有帮助。
干杯。