Hey guys,
I’m using the latest android SDK to monitor estimote beacons, but something is going wrong with monitoring proecss. I’m using background service to scan continously and track “enter” and “exit” trigger. But it’s triggering multiple times (Enter and Exit ) both event even If I’m not doing any physical movement with my device.I don’t know , I’m bit confused with configuration or the changes If it is required with my beacon from cloud as I have just ordered recently.
Following is my code
public class BeaconService extends Service {
private BeaconManager beaconManager;
private String UUID = "DEFAULT";
public BeaconService() {
}
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
public void onCreate() {
super.onCreate();
beaconManager = new BeaconManager(getApplicationContext());
beaconManager.setMonitoringListener(new BeaconManager.MonitoringListener() {
@Override
public void onEnteredRegion(Region region, List<Beacon> list) {
System.out.println("Entered Called!!! " + region.getProximityUUID() + " Minor : " + list.get(0).getMinor());
showNotification("SmartCall","You entered!");
}
@Override
public void onExitedRegion(Region region) {
// could add an "exit" notification too if you want (-:
System.out.println("Exited Called!!! "+ region.getProximityUUID() + " Minor : "+ region.getMinor());
showNotification("SmartCall","You exited!");
}
});
beaconManager.connect(new BeaconManager.ServiceReadyCallback() {
@Override
public void onServiceReady() {
try {
beaconManager.startMonitoring(new Region("region1", UUID, 4612, 17441));
beaconManager.startMonitoring(new Region("region2", UUID, 1823, 27189));
beaconManager.startMonitoring(new Region("region3", UUID, 58647, 51356));
System.out.println("BeaconManger Connected!");
} catch (RemoteException e) {
e.printStackTrace();
}
}
});
}
public void showNotification(String title, String message) {
Intent notifyIntent = new Intent(this, MainActivity.class);
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivities(this, 0,
new Intent[]{notifyIntent}, PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification = new Notification.Builder(this)
.setSmallIcon(android.R.drawable.ic_dialog_info)
.setContentTitle(title)
.setContentText(message)
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.build();
notification.defaults |= Notification.DEFAULT_SOUND;
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(10, notification);
}
}
Kindly help me to sort out this issue, Why it is triggering mutiple times both enter and exit even if I’m not doing any physical movement.?
Thanks