Question

I'm trying out the sample with some iBeacons. Everything works as expected in the RangingActivity. I can see all the info about the iBeacon. However, I am trying to modify the didEnterREgion method of the notifier and I am running into a problem. Even though technically something is "found" when I try to do region.getProximityUuid() it returns null. I can't figure out a good way to get this info on the first connect? Am I doing something wrong?

Here is a snippet of my modified method:

public void didEnterRegion(Region region) {
      logToDisplay("I just saw an iBeacon for the first time!"); 
    String ttag = "calbeaconM";
    Log.v(ttag,"proxUUID: " + region.getProximityUuid());
    //Log.v(ttag,"distance: " + region.getAccuracy());
    Log.v(ttag,"major: " + region.getMajor());
    Log.v(ttag,"minor: " + region.getMinor());
    //Log.v(ttag,"proximity: " + region.getProximity());
    Log.v(ttag,"hash: " + region.hashCode());
    //Log.v(ttag,"rssi: " + region.getRssi());


    if(region.getProximityUuid() != null){

    }
 }

and the logcat output:

proxUUID: null
major: null
minor: null
hash: -1975428096

Can't figure out where I am going wrong.

Était-ce utile?

La solution

Your code does not show how you set up your region to monitor, but I suspect you set up an all null region like in the sample code:

   iBeaconManager.startMonitoringBeaconsInRegion(
       new Region("myMonitoringUniqueId", null, null, null));

If this is how you started monitoring, then what you are seeing is entirely expected. The region object you get as a parameter in the didEnterRegion method has the same field values as the region you passed to the startMonitoringBeaconsInRegion method. If you constructed your region with the last three parameters being null (proximityUuid, major, minor), that is what you get back.

Why does it work this way? When you start monitoring, you are basically saying "tell me about iBeacons that match these identifiers". The equivalent method call does the same thing on iOS and let's you set null major and minor values, but Android allows you to set the proximityUuid to null as well, effectively saying, "tell me about any iBeacon I see at all".

If you want to see the identifiers of the iBeacons you detect, there are two ways to do so:

  1. Specify the identifiers when you start monitoring:

    iBeaconManager.startMonitoringBeaconsInRegion(
        new Region("myMonitoringUniqueId", "2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6", 1, 100));
    
  2. Also start ranging when you start monitoring. The didRangeBeaconsInRegion(Collection<IBeacon> iBeacons, Region region) ranging callback gives you a list of all iBeacons that are seen, with all identifiers populated.

See the example code for more details.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top