[英]Hello I want to detect using a Bluetooth iBeacon, but it does not work well. How can I solve it?
Hello I want to detect using a Bluetooth iBeacon, but it does not work well.您好,我想使用蓝牙 iBeacon 进行检测,但效果不佳。 How can I solve it?我该如何解决? I am testing by connecting with a real mobile phone, not an emulator.我通过连接真正的手机而不是模拟器进行测试。
2020-06-13 22:42:01.729 26437-26728/com.example.beacon D/BluetoothAdapter: STATE_ON 2020-06-13 22:42:01.729 26437-26728/com.example.beacon D/BluetoothLeScanner: could not find callback wrapper 2020-06-13 22:42:08.353 26437-26728/com.example.beacon D/BluetoothAdapter: STATE_ON 2020-06-13 22:42:08.353 26437-26728/com.example.beacon D/BluetoothLeScanner: could not find callback wrapper 2020-06-13 22:42:01.729 26437-26728/com.example.beacon D/BluetoothAdapter:STATE_ON 2020-06-13 22:42:01.729 26437-26728/com.example.beacon D/BluetoothLeScanner:找不到回调包装器 2020-06-13 22:42:08.353 26437-26728/com.example.beacon D/BluetoothAdapter: STATE_ON 2020-06-13 22:42:08.353 26437-26728/com.example.beacon D/BluetoothLeScanner: 可以找不到回调包装器
Is that it continues to be filmed.是不是还在继续拍。
public class MainActivity extends AppCompatActivity implements BeaconConsumer {
protected static final String TAG = "MonitoringActivity";
private BeaconManager beaconManager;
PermissionListener permissionlistener = new PermissionListener() {
@Override
public void onPermissionGranted() {
Toast.makeText(MainActivity.this, "Permission Granted", Toast.LENGTH_SHORT).show();
}
@Override
public void onPermissionDenied(List<String> deniedPermissions) {
Toast.makeText(MainActivity.this, "Permission Denied\n" + deniedPermissions.toString(), Toast.LENGTH_SHORT).show();
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
beaconManager = BeaconManager.getInstanceForApplication(this);
// To detect proprietary beacons, you must add a line like below corresponding to your beacon
// type. Do a web search for "setBeaconLayout" to get the proper expression.
beaconManager.getBeaconParsers().add(new BeaconParser().
setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"));
beaconManager.bind(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
beaconManager.unbind(this);
}
@Override
public void onBeaconServiceConnect() {
beaconManager.removeAllMonitorNotifiers();
beaconManager.addMonitorNotifier(new MonitorNotifier() {
@Override
public void didEnterRegion(Region region) {
Log.i(TAG, "I just saw an beacon for the first time!");
}
@Override
public void didExitRegion(Region region) {
Log.i(TAG, "I no longer see an beacon");
}
@Override
public void didDetermineStateForRegion(int state, Region region) {
Log.i(TAG, "I have just switched from seeing/not seeing beacons: "+state);
}
});
try {
beaconManager.startMonitoringBeaconsInRegion(new Region("E2C56DB5-DFFB-48D2-B060-D0F5A71096E0", null, null, null));
} catch (RemoteException e) { }
}
}
Make sure you have declared FINE_LOCATION permission in your AndroidManifest.xml and you go through the steps to obtain that permission from the user .确保您已在您的 AndroidManifest.xml 和go 中声明了 FINE_LOCATION 权限,以从用户那里获得该权限。
Once you have completed those steps, if you still see these messages, read here: https://stackoverflow.com/a/42821272/1461050完成这些步骤后,如果您仍然看到这些消息,请在此处阅读: https://stackoverflow.com/a/42821272/1461050
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.