Nothing is wrong, this is how beacon monitoring works. When you monitor, you get notified when any beacon matching a wildcard pattern defined by your Region is detected. This notification tells you that a matching beacon was detected, and provides a reference to the Region object being monitored.
In the example shown, the defined Region has null for each of the three beacon identifiers, meaning it will match any beacon. It therefore provides only a single callback when any beacon is detected and does not tell you the identifiers of what matched.
You have two choices for getting access to the identifiers:
If you only care about a couple of beacons, you can monitor for multiple explicit regions like: Region region1 = new Region("first beacon", "2F234454-CF6D-4A0F- ADF2-F4911BA9FFA6", "1", " 2");
This will give you a Region object in the callback with all identifiers set.
Use ranging APIs which give you a callback every second with a list of all beacons with identifiers matching the defined region.
Below is a full Activity implementation for option 1. When you run this, you will see the following in LogCat:
D/MonitoringActivity(31644): starting monitoring
D/MonitoringActivity(31644): Entered region: null null null
D/MonitoringActivity(31644): Entered region: 2f234454-cf6d-4a0f-adf2-f4911ba9ffa6 1 1
Note that the first region entry will all null identifiers is sent because the activity is also monitoring an all null region.
public class MonitoringActivity extends Activity implements BeaconConsumer, MonitorNotifier {
protected static final String TAG = "MonitoringActivity";
private BeaconManager mBeaconManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_monitoring);
mBeaconManager = BeaconManager.getInstanceForApplication(this);
mBeaconManager.bind(this);
}
@Override
public void onBeaconServiceConnect() {
try {
mBeaconManager.setMonitorNotifier(this);
mBeaconManager.startMonitoringBeaconsInRegion(new Region("all beacons region", null, null, null));
mBeaconManager.startMonitoringBeaconsInRegion(new Region("region 1", Identifier.parse("2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6"), Identifier.parse("1"), Identifier.parse("1")));
mBeaconManager.startMonitoringBeaconsInRegion(new Region("region 2", Identifier.parse("2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6"), Identifier.parse("1"), Identifier.parse("2")));
Log.d(TAG, "starting monitoring");
} catch (RemoteException e) {
Log.e(TAG, "can't monitor", e);
}
}
@Override
public void didEnterRegion(Region region) {
Log.d(TAG, "Entered region: "+region.getId1()+" "+region.getId2()+" "+region.getId3());
}
@Override
public void didExitRegion(Region region) {
Log.d(TAG, "Exited region: "+region.getId1()+" "+region.getId2()+" "+region.getId3());
}
@Override
public void didDetermineStateForRegion(int state, Region region) {
}
}