onIBeaconServiceConnect() is not getting called in

2019-08-15 06:26发布

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

3条回答
甜甜的少女心
2楼-- · 2019-08-15 06:54

adding

manifestmerger.enabled=true

in project.properties worked for me!

Source

查看更多
Explosion°爆炸
3楼-- · 2019-08-15 06:57

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>  
查看更多
Anthone
4楼-- · 2019-08-15 06:57

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.

查看更多
登录 后发表回答