这是我第一次使用beacon和android,有人可以帮助我在这里错过的内容吗?我正在使用信标涡流仪。 在startMonitoringBeaconsInRegion之后,它显示了0个设备被抽出
依赖项:
-实现'org.altbeacon:android-beacon-library:2 +'
源代码:
package com.XXX.yyyy.summa;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Parcelable;
import android.os.RemoteException;
import android.util.Log;
import org.altbeacon.beacon.Beacon;
import org.altbeacon.beacon.BeaconConsumer;
import org.altbeacon.beacon.BeaconManager;
import org.altbeacon.beacon.BeaconParser;
import org.altbeacon.beacon.Identifier;
import org.altbeacon.beacon.MonitorNotifier;
import org.altbeacon.beacon.Region;
import java.util.Collection;
import java.util.Iterator;
import static com.kone.schinnas.summa.MonitoringActivity.TAG;
public class MyActivity extends Activity implements BeaconConsumer, MonitorNotifier {
private BeaconManager mBeaconManager;
public void onResume() {
super.onResume();
mBeaconManager = BeaconManager.getInstanceForApplication(this.getApplicationContext());
// Detect the main Eddystone-UID frame:
mBeaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout(BeaconParser.EDDYSTONE_UID_LAYOUT));
mBeaconManager.bind(this);
}
@Override
public void onBeaconServiceConnect() {
Region region = new Region("all-beacons-region", null, null, null);
mBeaconManager.addMonitorNotifier(this);
try {
mBeaconManager.startMonitoringBeaconsInRegion(region);
int i = 0;
} catch (RemoteException e) {
e.printStackTrace();
}
}
public void didEnterRegion(Region region) {
Log.d(TAG, "I detected a beacon in the region with namespace id " + region.getId1() +
" and instance id: " + region.getId2());
}
public void didExitRegion(Region region) {
}
public void didDetermineStateForRegion(int state, Region region) {
}
@Override
public void onPause() {
super.onPause();
mBeaconManager.unbind(this);
}
}