您好,我想使用蓝牙 iBeacon 进行检测,但效果不佳。我该如何解决?

Hello I want to detect using a Bluetooth iBeacon, but it does not work well. How can I solve it?

您好,我想使用蓝牙 iBeacon 进行检测,但效果不佳。我该如何解决? 我正在通过连接真实移动设备 phone 而不是模拟器进行测试。

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

是不是还要继续拍

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) {    }
    }
}

确保您已在 AndroidManifest.xml 中声明了 FINE_LOCATION 权限并且您 go through the steps to obtain that permission from the user.

完成这些步骤后,如果您仍然看到这些消息,请阅读此处: