Beacon Android didEnterRegion未调用

时间:2016-11-13 16:36:28

标签: android beacon

我买了以下Beacon(Link)。

我经历了这个tutorial并最终结束了这样:

public class MainActivity extends Activity implements BeaconConsumer {

    private BeaconManager beaconManager;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        beaconManager = BeaconManager.getInstanceForApplication(this);
        beaconManager.getBeaconParsers().add(new BeaconParser().
                setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
        beaconManager.bind(this);
    }

    @Override
    public void onBeaconServiceConnect() {
        Log.d(TAG, "connectedService");
        beaconManager.addMonitorNotifier(new MonitorNotifier() {
            @Override
            public void didEnterRegion(Region region) {
                try {
                    Log.d("beaconTest", "didENTERRegion");
                    beaconManager.startRangingBeaconsInRegion(region);
                } catch (RemoteException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void didExitRegion(Region region) {
                try {
                    Log.d("beaconTest", "didEXITRegion");
                    beaconManager.stopRangingBeaconsInRegion(region);
                } catch (RemoteException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void didDetermineStateForRegion(int i, Region region) {

            }
        });

        beaconManager.addRangeNotifier(new RangeNotifier() {
            @Override
            public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
                for (Beacon beacon : beacons){
                    Log.d("beaconTest", "distance: " +
                            beacon.getDistance() + "id: " +
                            beacon.getId1() + "/" +
                            beacon.getId2() + "/" +
                            beacon.getId3());
                }
            }
        });

        try {
            beaconManager.startMonitoringBeaconsInRegion(new Region("", null, null, null));
        } catch (RemoteException e) {
            e.printStackTrace();
        }

    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        beaconManager.unbind(this);
    }

}

我的问题是,从未调用过didEnterRegion()方法,我无法弄清楚原因。最小的SDK版本设置为18,我在手机上激活了蓝牙并请求了应用程序的许可。我可以找到第三方应用程序的灯塔,但不能找到我的代码。有人能告诉我我能做些什么来解决这个问题吗?

这是我的调试输出:

$ adb shell am start -n "com.test/com.test.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -D
Connecting to com.test
Connected to the target VM, address: 'localhost:8600', transport: 'socket'
I/art: Late-enabling -Xcheck:jni
W/ActivityThread: Application com.test is waiting for the debugger on port 8100...
I/System.out: Sending WAIT chunk
I/art: Debugger is active
I/System.out: Debugger has connected
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: debugger has settled (1381)
W/System: ClassLoader referenced unknown path: /data/app/com.test-1/lib/arm
I/InstantRun: Instant Run Runtime started. Android package is com.test, real application class is null.
W/System: ClassLoader referenced unknown path: /data/app/com.test-1/lib/arm
D/BeaconParser: Parsing beacon layout: m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25
D/BeaconParser: Parsing beacon layout: m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24
D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
W/BluetoothCrashResolver: Can't read macs from BluetoothCrashResolverState.txt
W/ModelSpecificDistanceCalculator: App has no android.permission.INTERNET permission.  Cannot check for distance model updates
I/Adreno: QUALCOMM build                   : 166ada0, Ifd751822f5
          Build Date                       : 01/26/16
          OpenGL ES Shader Compiler Version: XE031.06.00.05
          Local Branch                     : AU12_SBA
          Remote Branch                    : 
          Remote Branch                    : 
          Reconstruct Branch               : 
I/OpenGLRenderer: Initialized EGL, version 1.4
D/BeaconsEverywhere: connectedService
D/BluetoothAdapter: STATE_ON
D/BluetoothLeScanner: could not find callback wrapper
D/BluetoothAdapter: STATE_ON

提前致谢。

0 个答案:

没有答案