onIBeaconServiceConnect() is not getting called in android

时光毁灭记忆、已成空白 提交于 2019-12-23 03:28:09

问题


I am using AndroidIbeacon library released by radiusnetworks and I am able to run their demo app successfully. But when I add that to my application onIBeaconServiceConnect() method is not called.

Below my code,

 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) {
    }
   }

  }

Kindly help me to solve this issue. thanks


回答1:


If manifest merging does not work, try this (worked for me):

Add the following service declarations to your AnroidManifest.xml, replacing {my app's package name} with the fully qualified package name of your Android application.

    <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>  



回答2:


The most common cause of this issue is that the proper entries to start the library's service are not in the project AndroudManifest.xml file. Your new project must pull in these entries from the library's manifest using a feature called manifest merging.

Make sure you have followed the setup instructions here. If using Eclipse, verify your project.properties has manifestmerger.enabled=true.




回答3:


adding

manifestmerger.enabled=true

in project.properties worked for me!

Source



来源:https://stackoverflow.com/questions/23624467/onibeaconserviceconnect-is-not-getting-called-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!