응용 프로그램을 만들었습니다.이 응용 프로그램은 비콘 범위를 지정하고 4 개 이상의 비컨이 원거리에 배치되었을 때 위치를 계산합니다.새로운 안드로이드 인 텐트를 열면 범위 찾기가 중지됩니다.
문제는 포지션을 보여주고 싶을 때 새로운 의도를 시작해야하기 때문에 메인 액티비티가 여전히 포 그라운드에 있지 않다는 것입니다. 약 5 초 후에 비컨의 거리가 멈추고 위치도 계산됩니다. 왜냐하면 비컨의 거리가 더 이상 변하지 않기 때문입니다.
계속해서 비콘을 측정 할 가능성이 있습니까? 내 주요 활동에서 비동기 작업을 시작하려고 시도했지만 작동하지 않습니다. 어쩌면 실수가있을 수 있습니다. 모르겠습니다. 여기
내 비동기 작업의 코드와 OnBeaconServiceConnect()이다 :public class Monitor_Screen extends Activity implements BeaconConsumer,
SensorEventListener {
private class asyncThread extends AsyncTask<Activity, Void, BeaconManager> {
@Override
protected BeaconManager doInBackground(Activity... arg0) {
// TODO Auto-generated method stub
Thread.currentThread().setName("BeaconManagerThread");
Application myApplication = new Application();
// BeaconManager
myBeaconManager = BeaconManager.getInstanceForApplication(myApplication);
myBeaconManager
.getBeaconParsers()
.add(new BeaconParser()
.setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
myBeaconManager.setBackgroundScanPeriod(TimeUnit.SECONDS.toMillis(1));
myBeaconManager.bind(Monitor_Screen.this);
// Region
myRegion = new Region("all beacons", null, null, null);
startService(Monitor_Screen.this.getIntent());
return myBeaconManager;
}
}
@Override
public void onBeaconServiceConnect() {
// // range beacons on connect
try {
myBeaconManager.startRangingBeaconsInRegion(myRegion);
} catch (RemoteException e) {
Toast.makeText(getApplicationContext(), e.getMessage(),
Toast.LENGTH_LONG).show();
}
myBeaconManager.setRangeNotifier(new RangeNotifier() {
public void didRangeBeaconsInRegion(Collection<Beacon> beacons,
Region myRegion) {
if (beacons.size() > 0) {
Iterator<Beacon> myIterator = beacons.iterator();
while (myIterator.hasNext()) {
Beacon tempBeacon = myIterator.next();
MyBeacon myBeacon = new MyBeacon(tempBeacon.getId1(),
tempBeacon.getId2(), tempBeacon.getId3(),
tempBeacon.getBluetoothAddress(), tempBeacon
.getRssi(), tempBeacon.getDistance(),
tempBeacon.getTxPower(), System
.currentTimeMillis(),
new Position(0, 0));
boolean isIn = false;
for (MyBeacon blub : myVector) {
if (blub.getBTAdress().equals(
myBeacon.getBTAdress())) {
isIn = true;
blub.distance = myBeacon.getDistance();
}
}
if (!isIn)
myVector.add(myBeacon);
}
}
logBeaconData();
for (int i = 0; i < myVector.size(); i++) {
if (System.currentTimeMillis()
- myVector.get(i).getTimeStamp() > 10000) {
myVector.remove(i);
}
}
}
});
try {
myBeaconManager.startMonitoringBeaconsInRegion(myRegion);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
myBeaconManager.setMonitorNotifier(new MonitorNotifier() {
@Override
public void didExitRegion(Region arg0) {
// TODO Auto-generated method stub
}
@Override
public void didEnterRegion(Region arg0) {
// TODO Auto-generated method stub
}
@Override
public void didDetermineStateForRegion(int arg0, Region arg1) {
// TODO Auto-generated method stub
}
});
}
불행히도이 솔루션은 나에게 적합하지 않습니다. 새 프로젝트를 시작하고 ReferenceApplication을 테스트했지만 작동하지 않습니다. 응용 프로그램이 충돌 함 : ( –
참조 응용 프로그램의 수정되지 않은 버전을 실행 해보십시오. 충돌이 표시되면 스택 추적에 대한 링크를 붙여 넣으십시오. – davidgyoung