Android の radius ネットワークの IBeacon SDK を使用しています。現在、1 つのアクティビティと 1 つのサービスで IBeaconManager を使用しています。アプリが最初に起動すると、アクティビティはその iBeaconManager オブジェクトをバインドしますonIBeaconServiceConnect
が、呼び出されることはありません。測距または監視関数 ex を呼び出す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)
true を返しています。
サービスを開始すると (アクティビティからアンバインドしてサービスにバインド)、バインドが正常に機能し、ビーコンの監視を開始できます。その後、アクティビティを再度開くと (サービスからバインドを解除してアクティビティにバインドした後)、アクティビティでも機能するようになりました。
そのため、アプリが最初に起動したときのみonIBeaconServiceConnect()
、アクティビティに対して が呼び出されません。
どんな助けでも大歓迎です。
アップデート
MyActivity
(BaseActivity
は のサブクラスです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");
});
}
}