0

我在 android 上使用来自 radius 网络的 IBeacon SDK。我目前在一项活动和一项服务中使用 IBeaconManager。当应用程序第一次启动时,Activity 会绑定它的 iBeaconManager 对象,但onIBeaconServiceConnect永远不会被调用。调用任何测距或监控函数startRangingBeaconsInRegion(region)都会抛出 RemoteException:

 The IBeaconManager is not bound to the service.  Call iBeaconManager.bind(IBeaconConsumer consumer) and wait for a callback to onIBeaconServiceConnect()

出人意料的是,iBeaconMananger.isBound(myActivity)正在回归真实。

现在,当我启动我的服务(从我的活动解除绑定并绑定到我的服务)时,绑定工作正常,我可以开始监视信标。如果那时,我再次打开活动(从我的服务解除绑定并绑定到我的活动之后),它现在也可以在我的活动中使用。

因此,只有在应用程序首次启动时,onIBeaconServiceConnect()才不会为我的 Activity 调用。

任何帮助是极大的赞赏。


更新

MyActivityBaseActivity是 的子类Activity):

public class MyActivity extends BaseActivity implements IBeaconConsumer {

    private IBeaconManager iBeaconManager;
    LocationManager locationManager;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.new_survey);

        locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

        ...

        iBeaconManager = IBeaconManager.getInstanceForApplication(this);
        iBeaconManager.bind(this);
    }

    @Override
    public void onIBeaconServiceConnect() {
        Log.d("mytag","beacon service connected");
        iBeaconManager.setRangeNotifier(new RangeNotifier() {
            @Override
            public void didRangeBeaconsInRegion(Collection<IBeacon> iBeacons, Region region) {
                Log.d("mytag","did range beacons");

        });
    }
}
4

1 回答 1

0

我最终将 beaconManager 移动到我的Application子类,而不是在我的活动中使用它。

于 2014-06-11T20:44:15.833 回答