我正在开发一个Android
检测iBeacon
. 现在我的问题是,在LogCat
我可以看到信标的正确名称以及 IP 地址
BtGatt.btif btif_gatc_update_properties BLE 设备名称=.. BtGatt GattService onScanResult() IP 地址
但是该方法仍然作为集合onBeaconServiceConnect()
进入部分(为0)。我已经在这里阅读了有关此主题的主题并搜索了互联网,但找不到答案。else
Size
我的代码:
public class RangingActivity extends Activity implements BeaconConsumer {
protected static final String TAG = "RangingActivity";
private BeaconManager beaconManager = BeaconManager.getInstanceForApplication(this);
private BluetoothAdapter btAdapt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ranging);
beaconManager.setBackgroundScanPeriod(1000);
beaconManager.bind(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
beaconManager.unbind(this);
}
@Override
protected void onPause() {
super.onPause();
}
@Override
protected void onResume() {
super.onResume();
}
@Override
public void onBeaconServiceConnect() {
beaconManager.setRangeNotifier(new RangeNotifier() {
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
logToDisplay("Number of beacons detected: "+beacons.size());
if (beacons.size() > 0) {
EditText editText = (EditText)RangingActivity.this
.findViewById(R.id.rangingText);
Beacon firstBeacon = beacons.iterator().next();
logToDisplay("The first beacon "+firstBeacon.toString());
}else{
logToDisplay("No beacon");
}
}
});
try {
beaconManager.startRangingBeaconsInRegion(new Region("myRangingUniqueId", null, null, null));
} catch (RemoteException e) { }
}
private void logToDisplay(final String line) {
runOnUiThread(new Runnable() {
public void run() {
EditText editText = (EditText)RangingActivity.this
.findViewById(R.id.rangingText);
editText.append(line+"\n");
}
});
}
}