Hello folks,
I need an help.
I building an app with Proximity Location as the indoor does not have SDK yet for Android.
I’m using Estimote sample code . In fact I just need to be sure if a user is at an alley or another.
My issue I’m not receiving notification for the correct beacon .The app still sending notification for all three beacons even if the user is not moving.
When the user moves ,the notification sent by the app does not corresponds to the beacon located in the alley.
Below is the code
public class MainActivity extends AppCompatActivity {
private static final Map<String, List<String>> PLACES_BY_BEACONS;
static {
Map<String, List<String>> placesByBeacons = new HashMap<>();
placesByBeacons.put("16923:52747", new ArrayList<String>() {{
add("Sandwiches");
add("Green & Green Salads");
add("Mini Panini");
}});
placesByBeacons.put("28592:17738", new ArrayList<String>() {{
add("Mini Panini");
add("Green & Green Salads");
add("Heavenly Sandwiches");
}});
placesByBeacons.put("14286:46651", new ArrayList<String>() {{
add("candy");
add("coke");
add("juice");
}});
PLACES_BY_BEACONS = Collections.unmodifiableMap(placesByBeacons);
}
private List<String> placesNearBeacon(Beacon beacon) {
String beaconKey = String.format("%d:%d", beacon.getMajor(), beacon.getMinor());
if (PLACES_BY_BEACONS.containsKey(beaconKey)) {
return PLACES_BY_BEACONS.get(beaconKey);
}
return Collections.emptyList();
}
private BeaconManager beaconManager;
private Region region;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
beaconManager = new BeaconManager(this);
beaconManager.setRangingListener(new BeaconManager.RangingListener() {
@Override
public void onBeaconsDiscovered(Region region, List<Beacon> list) {
if (!list.isEmpty()) {
Beacon nearestBeacon = list.get(0);
List<String> places = placesNearBeacon(nearestBeacon);
Toast.makeText(getApplicationContext(),places.toString(),Toast.LENGTH_SHORT).show();
}
}
});
//fromString(“contain the uuid of beacon) in the estimote cloud
region = new Region(“ranged region”, UUID.fromString(”"), null, null);
}
@Override
protected void onResume() {
super.onResume();
SystemRequirementsChecker.checkWithDefaultDialogs(this);
beaconManager.connect(new BeaconManager.ServiceReadyCallback() {
@Override
public void onServiceReady() {
beaconManager.startRanging(region);
}
});
}
@Override
protected void onPause() {
beaconManager.stopRanging(region);
super.onPause();
}
}