问题描述
当我使用其他商业信标扫描仪时,信标被正常捕获,但是当我使用我制作的这个源代码时,它们根本没有被捕获。
确认“didRangeBeaconsInRegion”函数继续工作,但信标数一直返回0,请检查问题所在。
public class MainActivity extends AppCompatActivity implements BeaconConsumer {
TextView textView;
private BeaconManager beaconManager;
String beaconUUID="00000000000000000000000000000054"; // beacon -uuid
private static final int PERMISSION_REQUEST_COARSE_LOCATION = 1;
private String TAG = "CHS_BEA";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView=findViewById(R.id.tv_message);
beaconManager = BeaconManager.getInstanceForApplication(this);
beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout(BeaconParser.EDDYSTONE_UID_LAYOUT));
beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout(BeaconParser.EDDYSTONE_TLM_LAYOUT));
beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout(BeaconParser.EDDYSTONE_URL_LAYOUT));
beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25\""));
beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:0-3=4c000215,p:24-24"));
//beaconManager.setBackgroundMode(true);
beaconManager.bind(this);
}// onCreate()..
@Override
public void onBeaconServiceConnect() {
beaconManager.removeAllMonitorNotifiers();
Log.i(TAG,"onBeaconServiceConnect Start");
beaconManager.addRangeNotifier(new RangeNotifier() {
@Override
public void didRangeBeaconsInRegion(Collection<Beacon> beacons,Region region) {
Log.i(TAG,"didRangeBeaconsInRegion Start -> " + region.toString());
Log.i(TAG,"didRangeBeaconsInRegion beacons -> " + beacons.size());
}
});
beaconManager.addMonitorNotifier(new MonitorNotifier() {
@Override
public void didEnterRegion(Region region) {
Log.i(TAG,"I just saw an beacon for the first time!");
Toast.makeText(MainActivity.this,"didEnterRegion - 비콘 연결됨",Toast.LENGTH_SHORT).show();
textView.setText("Beacon connected");
}
@Override
public void didExitRegion(Region region) {
Log.i(TAG,"I no longer see an beacon");
Toast.makeText(MainActivity.this,"didExitRegion - 비콘 연결 끊김",Toast.LENGTH_SHORT).show();
textView.setText("Beacon disconnected");
}
@Override
public void didDetermineStateForRegion(int state,"I have just switched from seeing/not seeing beacons: "+state);
}
});
try {
beaconManager.startMonitoringBeaconsInRegion(new Region("beacon",null,null));
} catch (remoteexception e) { }
try
{
beaconManager.startRangingBeaconsInRegion(new Region("beacon",null));
}
catch (remoteexception e)
{
}
}// onBeaconServiceConnect()..
@Override
public void onDestroy() {
super.onDestroy();
beaconManager.unbind(this);
}
@Override
public void onPointerCaptureChanged(boolean hasCapture) {
}
}// MainActivity 类..``
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)