Using iBeacons in a Cordova plugin i.e. outside of an Activity/Service

后端 未结 1 2055
刺人心
刺人心 2021-01-07 01:56

I\'m trying to write a Cordova plugin which interacts with the Radius Networks iBeacon library for Android. Now, I\'m aware the library is designed for use with an Activity/

1条回答
  •  一整个雨季
    2021-01-07 02:56

    Your empty bindService and unbindService methods are causing you problems. If your class were an Activity, Service or Application, these would all be implemented for you. If you want to make a custom class you have to provide an implementation.

    Without an implementation for the bindService method, the iBeaconManager.bind(this); line ends up accomplishing nothing, because it in turn has to call one of these methods. (Add log lines to those empty methods and you will see.) As a result, the IBeaconService never starts up and onIBeaconServiceConnect never gets called.

    Enough boring explanation -- it's time for a solution! The easiest thing to do is to chain these methods. Try something like:

    @Override
    public boolean bindService(Intent intent, ServiceConnection conn, int mode) {
        return context.bindService(intent, conn, mode);
    }
    
    @Override
    public void unbindService(ServiceConnection conn) {
        context.unbindService(conn);
    }
    

    0 讨论(0)
提交回复
热议问题