Hello,
I am trying to make an android app that will only allow you to login if you are in range of a beacon. I will have all of my beacons have the same UUID and will then identify which beacon it is with the major value.
So far I’ve got it to give a notification when a beacon with my unique UUID is in range but can’t figure out how to get the beacons Major value?
I followed step 2 of the Android tutorial (background monitoring) and created a java class called “BeaconChecker.java” instead of “MyApplication.java” like in the tutorial.
I know I need to use getMajor() but as I’m new to Java and Android I have no idea how to do this…
If I could get the Major before the showNotification() function and somehow pass it to LoginActivity.java I will be able to complete my application. Please see the code for monitoring for beacon and pushing notification in BeaconChecker.java class:
beaconManager = new BeaconManager(getApplicationContext());
beaconManager.connect(new BeaconManager.ServiceReadyCallback() {
@Override
public void onServiceReady() {
beaconManager.startMonitoring(new Region(
"monitored region",
UUID.fromString("MY UNIQUE UUID"),
null, null));
}
});
beaconManager.setMonitoringListener(new BeaconManager.MonitoringListener() {
@Override
public void onEnteredRegion(Region region, List<Beacon> list) {
##### Somehow get the beacon major id here and pass to LoginActivity.java #####
showNotification(
"Beacon Detected!",
"Login enabled.");
}
@Override
public void onExitedRegion(Region region) {
// could add an "exit" notification too if you want (-:
}
});
Any help would be very much appreciated! Thanks!