- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 AltBeacon 构建应用程序 库支持 Onyx Beacons (Beacon One) 和 Gimbal Beacons (Series 21)
我的测试设备是配备 Android 4.4.4 KitKat 和 Onyx Beacon 的 Nexus 7 2013。信标就在我的设备旁边不到一米的地方,我没有移动它。检测到信标并转到 didEnterRegion
然后在一分钟左右后转到 didExitRegion
然后循环重复。
我们还使用不同的 (Onyx) 信标在不同的设备(三星手机)上对此进行了测试。仍然出现问题。请注意,这仅发生在 Onyx Beacons (Beacon One) 上 。 <强> Gimbal Beacons (Series 21) 仅在范围内触发一次。
我使用的 Beacon Parser 字符串是否正确?我是否正确实现了这一点?我真的没有想法,我想支持这两个信标。
基础应用
public class BaseApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
startService(new Intent(this, BeaconMonitoringService.class));
}
}
BeaconMonitoringService
public class BeaconMonitoringService extends Service implements BeaconConsumer{
private Context context;
private BeaconService service;
private BeaconManager beaconManager;
private NotificationCompat.Builder notifBuilder;
@Override
public void onCreate(){
super.onCreate();
context = getBaseContext();
beaconManager = BeaconManager.getInstanceForApplication(this);
beaconManager.setBackgroundMode(true);
beaconManager.setBackgroundScanPeriod(1100l);
beaconManager.setBackgroundBetweenScanPeriod(15000l);
String[] beaconParsers = new String[] { "m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24", "m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25", "m:2-3=0203,i:14-19l,d:10-13,p:9-9" };
for(String beacon : beaconParsers){
Log.i("BeaconService","layout: "+beacon);
beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout(beacon));
}
beaconManager.bind(this);
}
@Override
public void onBeaconServiceConnect() {
beaconManager.setMonitorNotifier(new MonitorNotifier() {
private String log;
@Override
public void didEnterRegion(Region region) {
Beacon beacon = service.getBeacon(region.getId1().toString(), region.getId2().toString(), region.getId3().toString());
log = "I just saw a beacon for the first time! "+region.getId1()+" "+region.getId2()+" "+region.getId3();
Log.i("BeaconService", log);
sendNotification(beacon);
}
@Override
public void didExitRegion(Region region) {
Beacon beacon = service.getBeacon(region.getId1().toString(), region.getId2().toString(), region.getId3().toString());
log = "I no longer see a beacon";
Log.i("BeaconService", log);
}
@Override
public void didDetermineStateForRegion(int state, Region region) {
}
});
List<BackendRegion> regionList = Util.getRegionList();
for(BackendRegion region : regionList){
ArrayList<Beacon> beaconList = region.getBeacons();
for(Beacon beacon : beaconList){
try {
String beaconString = region.getUuid().toLowerCase() + " " + beacon.getMajor() + " " + beacon.getMinor();
service.addBeacon(beacon);
beaconManager.startMonitoringBeaconsInRegion(new Region(beacon.getIdentifier(), Identifier.parse(region.getUuid()),Identifier.parse(beacon.getMajor()),Identifier.parse(beacon.getMinor())));
} catch (RemoteException e) { }
}
}
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onDestroy(){
beaconManager.unbind(this);
super.onDestroy();
}
private void sendNotification(Beacon beacon, InteractiveImage interactiveImage) {
this.notifBuilder = new NotificationCompat.Builder(this)
.setAutoCancel(true)
.setContentTitle("Sample Beacon")
.setContentText("A beacon was detected")
.setSmallIcon(R.drawable.ic_launcher);
Intent notifyIntent = new Intent(this, NotificationActivity.class);
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notifyIntent, 0);
notifBuilder.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(Integer.parseInt(beacon.getId()), notifBuilder.build());
}
}
日志
12-11 15:45:24.103 I/BeaconService: I just saw a beacon for the first time! 20cae8a0-a9cf-11e3-a5e2-0800200c9a66 7 44512
12-11 15:45:24.784 D/BluetoothAdapter: stopLeScan()
12-11 15:45:39.698 D/BluetoothAdapter: startLeScan(): null
12-11 15:45:39.709 D/BluetoothAdapter: onClientRegistered() - status=0 clientIf=5
12-11 15:45:40.830 D/BluetoothAdapter: stopLeScan()
12-11 15:45:55.794 D/BluetoothAdapter: startLeScan(): null
12-11 15:45:55.804 D/BluetoothAdapter: onClientRegistered() - status=0 clientIf=5
12-11 15:45:56.985 D/BluetoothAdapter: stopLeScan()
12-11 15:46:11.920 D/BluetoothAdapter: startLeScan(): null
12-11 15:46:11.950 D/BluetoothAdapter: onClientRegistered() - status=0 clientIf=5
12-11 15:46:13.091 D/BluetoothAdapter: stopLeScan()
12-11 15:46:27.996 D/BluetoothAdapter: startLeScan(): null
12-11 15:46:28.016 D/BluetoothAdapter: onClientRegistered() - status=0 clientIf=5
12-11 15:46:29.147 D/BluetoothAdapter: stopLeScan()
12-11 15:46:29.227 I/BeaconService: I no longer see a beacon
12-11 15:46:44.121 D/BluetoothAdapter: startLeScan(): null
12-11 15:46:44.141 D/BluetoothAdapter: onClientRegistered() - status=0 clientIf=5
12-11 15:46:44.402 I/BeaconService: I just saw a beacon for the first time! 20cae8a0-a9cf-11e3-a5e2-0800200c9a66 7 44512
12-11 15:46:45.282 D/BluetoothAdapter: stopLeScan()
12-11 15:47:00.197 D/BluetoothAdapter: startLeScan(): null
12-11 15:47:00.197 D/BluetoothAdapter: onClientRegistered() - status=0 clientIf=5
12-11 15:47:01.328 D/BluetoothAdapter: stopLeScan()
12-11 15:47:16.343 D/BluetoothAdapter: startLeScan(): null
12-11 15:47:16.363 D/BluetoothAdapter: onClientRegistered() - status=0 clientIf=5
12-11 15:47:17.514 D/BluetoothAdapter: stopLeScan()
12-11 15:47:32.418 D/BluetoothAdapter: startLeScan(): null
12-11 15:47:32.428 D/BluetoothAdapter: onClientRegistered() - status=0 clientIf=5
12-11 15:47:33.540 D/BluetoothAdapter: stopLeScan()
12-11 15:47:48.494 D/BluetoothAdapter: startLeScan(): null
12-11 15:47:48.504 D/BluetoothAdapter: onClientRegistered() - status=0 clientIf=5
12-11 15:47:49.635 D/BluetoothAdapter: stopLeScan()
12-11 15:48:04.620 D/BluetoothAdapter: startLeScan(): null
12-11 15:48:04.630 D/BluetoothAdapter: onClientRegistered() - status=0 clientIf=5
12-11 15:48:05.771 D/BluetoothAdapter: stopLeScan()
12-11 15:48:20.706 D/BluetoothAdapter: startLeScan(): null
12-11 15:48:20.706 D/BluetoothAdapter: onClientRegistered() - status=0 clientIf=5
12-11 15:48:21.827 D/BluetoothAdapter: stopLeScan()
12-11 15:48:36.821 D/BluetoothAdapter: startLeScan(): null
12-11 15:48:36.831 D/BluetoothAdapter: onClientRegistered() - status=0 clientIf=5
12-11 15:48:37.962 D/BluetoothAdapter: stopLeScan()
12-11 15:48:52.917 D/BluetoothAdapter: startLeScan(): null
12-11 15:48:52.927 D/BluetoothAdapter: onClientRegistered() - status=0 clientIf=5
12-11 15:48:54.058 D/BluetoothAdapter: stopLeScan()
12-11 15:49:09.003 D/BluetoothAdapter: startLeScan(): null
12-11 15:49:09.003 D/BluetoothAdapter: onClientRegistered() - status=0 clientIf=5
12-11 15:49:10.154 D/BluetoothAdapter: stopLeScan()
12-11 15:49:10.214 I/BeaconService: I no longer see a beacon
最佳答案
一些提示:
检查 Onyx Beacon One 的广告率。为获得最佳效果,信标应以标准的 10Hz 进行广告。一些制造商降低了这种广告率以节省电池生命周期。如果您有一个以 1Hz 或更低频率进行广告的信标,它可能会开始被信标扫描仪定期遗漏。 (由于蓝牙 radio 噪声,并非 100% 的数据包都被检测到。)
如果您发现广告频率为 1 Hz 或更低,请尽可能提高广告频率,问题应该会消失。
如果你不能提高信标的广告率,你可以减慢Android Beacon Library的扫描率。 给它更多的时间来收集信标数据包。默认情况下,它使用 1.1 秒的扫描周期。您可以使用如下代码行将其减慢到 5 秒。这将更可靠地与不经常做广告的信标一起工作,但也会让您对区域进入/退出的响应时间变慢。 beaconManager.setForegroundScanPeriod(5000l);
关于android - OnyxBeacons 的 AltBeacon 不稳定,循环通过 didEnterRegion 和 didExitRegion 重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34218739/
我正在使用 AltBeacon 构建应用程序 库支持 Onyx Beacons (Beacon One) 和 Gimbal Beacons (Series 21) 我的测试设备是配备 Android
我是一名优秀的程序员,十分优秀!