首先,我所做的类似于链接(Android iBeacon Library - How to bind IBeaconManager to service in remote process):
- 定义了我自己的MyIBeaconService,它扩展了Service并实现 了 IBeaconConsumer。它包含一个IBeaconManager成员,并提供相应的 API,例如绑定/取消绑定等。在onIBeaconServiceConnect()中,它设置MonitorNotifier和RangeNotifier,开始监视和测距,并在调用相应通知程序的回调时向活动广播Intent 。
- 主要活动绑定到MyIBeaconService并在onResume()中注册相应的BraodcastReceiver。
- 然后,当主要活动成功绑定到MyIBeaconService时,在 ServiceConnection::onServiceConnected() 中,我调用IBeaconManager.bind将MyIBe aconService 绑定到IBeaconService。
但是,从未调用过 MyIBeaconService::onIBeaconServiceConnect。根据上面链接的回答,我把生成的AndroidManifest.xml文件贴在下面:
1. MyIBeaconService的AndroidManifest.xml
<uses-sdk android:minSdkVersion="18" android:targetSdkVersion="19"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<application android:allowBackup="true">
<service android:name="com.xxx.ibeaconlib.MyIBeaconService">
</service>
<service android:enabled="true" android:exported="true" android:isolatedProcess="false" android:label="iBeacon" android:name="com.radiusnetworks.ibeacon.service.IBeaconService">
</service>
<service android:enabled="true" android:name="com.radiusnetworks.ibeacon.IBeaconIntentProcessor">
</service>
</application>
2.MyIBeaconService的project.properties
target=android-19
android.library=true
manifestmerger.enabled=true
android.library.reference.1=../../../Downloads/AndroidIBeaconLibrary
3.我的Android应用程序的AndroidManifest.xml
<uses-sdk android:minSdkVersion="18" android:targetSdkVersion="19"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme">
<activity android:label="@string/app_name" android:name="com.radiusnetworks.ibeaconreference.MonitoringActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:label="@string/app_name" android:name="com.radiusnetworks.ibeaconreference.RangingActivity">
<intent-filter>
</intent-filter>
</activity>
<activity android:label="@string/app_name" android:name="com.radiusnetworks.ibeaconreference.BackgroundActivity">
<intent-filter>
</intent-filter>
</activity>
<service android:name="com.xxx.ibeaconlib.MyIBeaconService">
</service>
<service android:enabled="true" android:exported="true" android:isolatedProcess="false" android:label="iBeacon" android:name="com.radiusnetworks.ibeacon.service.IBeaconService">
</service>
<service android:enabled="true" android:name="com.radiusnetworks.ibeacon.IBeaconIntentProcessor">
</service>
</application>
4. Android Application的project.properties
target=android-19
manifestmerger.enabled=true //please confirm this line is added and remove the comment then
android.library.reference.1=../../Documents/workspace/iBeaconLib