您好,我想使用蓝牙iBeacon进行检测,但是效果不佳。我该如何解决?
我正在通过连接真实的手机而不是仿真器进行测试。

2020-06-13 22:42:01.729 26437-26728 / com.example.beacon
D /蓝牙适配器: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:
找不到回调包装器

是它继续被拍摄。

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
完成这些步骤后,如果仍然看到这些消息,请阅读此处:https://stackoverflow.com/a/42821272/1461050

10-04 14:37