1

我正在使用 radiusnetworks 发布的 AndroidIbeacon 库,并且能够成功运行他们的演示应用程序。但是当我将它添加到我的应用程序时,不会调用 onIBeaconServiceConnect() 方法。

在我的代码下面,

 public class Sample extends Activity implements IBeaconConsumer {
  protected static final String TAG = "Sample";
  private IBeaconManager iBeaconManager = IBeaconManager
        .getInstanceForApplication(this);

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity);
    iBeaconManager.bind(this);
}

@Override
protected void onDestroy() {
    super.onDestroy();
    iBeaconManager.unBind(this);
}

@Override
public void onIBeaconServiceConnect() {
    iBeaconManager.setMonitorNotifier(new MonitorNotifier() {
        @Override
        public void didEnterRegion(Region region) {
            Log.i(TAG, "I just saw an iBeacon for the firt time!");
        }

        @Override
        public void didExitRegion(Region region) {
            Log.i(TAG, "I no longer see an iBeacon");
        }

        @Override
        public void didDetermineStateForRegion(int state, Region region) {
            Log.i(TAG,
                    "I have just switched from seeing/not seeing iBeacons: "
                            + state);
        }
    });

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

  }

请帮我解决这个问题。谢谢

4

3 回答 3

1

如果清单合并不起作用,试试这个(对我有用):

将以下服务声明添加到您的 AnroidManifest.xml,将 {my app's package name} 替换为您的 Android 应用程序的完全限定包名称。

    <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">
            <meta-data android:name="background" android:value="true" />
        <intent-filter 
           android:priority="1" >
            <action android:name="{my app's package name}.DID_RANGING" />
            <action android:name="{my app's package name}.DID_MONITORING" />
        </intent-filter>
    </service>  
于 2014-08-10T08:32:56.790 回答
0

添加

manifestmerger.enabled=true

在 project.properties 为我工作!

资源

于 2014-07-19T02:11:52.987 回答
0

此问题的最常见原因是启动库服务的正确条目不在项目 AndroudManifest.xml 文件中。您的新项目必须使用称为清单合并的功能从库的清单中提取这些条目。

确保您已按照此处的设置说明进行操作。如果使用 Eclipse,请验证您的 project.properties 是否具有manifestmerger.enabled=true.

于 2014-05-13T10:55:21.977 回答