Is Monitoring Region still running when Phone Sleep / Lock?

Hi, i’m new in iBeacon Development,

i want to ask about beacon Monitoring, is Beacon Monitoring Region stil running when phone is sleep or lock ?

because when i see my LogCat, estimote beacon startLeScan and stopLeScan not running again after device sleep/lock and my notification in entered region not trigered

i’m create a services for handle Beacon Monitoring in background,
my services is always on even my app is destroy/kill/force close,
when user force stop my services, it will run again automatically.

but my problem in monitoring region when phone sleep/lock, my service stil running but scanLe stop running

there is my log cat

05-12 13:20:38.613  18619-18619/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerSetupReceiver_CheckingService_AlarmManagerSetEvery_10_Second
05-12 13:20:49.613  18619-18619/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerEventReceiver.onReceive() called
05-12 13:20:49.613  18727-18727/proximizer.ibeacon.adins.mobileque:my_process D/com.hascode.android.scheduler﹕ event received in service: Tue May 12 13:20:49 GMT+07:00 2015
05-12 13:20:49.613  18727-18727/proximizer.ibeacon.adins.mobileque:my_process I/EstimoteSDK﹕ com.estimote.sdk.BeaconManager.startMonitoring:403 Region already monitored but that's OK: Region{identifier=rid, proximityUUID=b9407f30-f5f8-466e-aff9-25556b57fe6d, major=null, minor=null}
05-12 13:20:49.633  18727-18741/proximizer.ibeacon.adins.mobileque:my_process D/BluetoothAdapter﹕ startLeScan(): null
05-12 13:20:49.633  18619-18619/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerSetupReceiver_CheckingService_StatusRunning
05-12 13:20:49.633  18727-18739/proximizer.ibeacon.adins.mobileque:my_process D/BluetoothAdapter﹕ onClientRegistered() - status=0 clientIf=5
05-12 13:20:54.653  18727-18741/proximizer.ibeacon.adins.mobileque:my_process D/BluetoothAdapter﹕ stopLeScan()
05-12 13:20:54.663  18619-18619/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerSetupReceiver_CheckingService_StatusRunning
05-12 13:20:56.703  18727-18741/proximizer.ibeacon.adins.mobileque:my_process D/BluetoothAdapter﹕ startLeScan(): null
05-12 13:20:56.703  18727-18738/proximizer.ibeacon.adins.mobileque:my_process D/BluetoothAdapter﹕ onClientRegistered() - status=0 clientIf=5
05-12 13:21:01.713  18727-18741/proximizer.ibeacon.adins.mobileque:my_process D/BluetoothAdapter﹕ stopLeScan()
05-12 13:21:03.763  18619-18619/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerSetupReceiver_CheckingService_StatusRunning
05-12 13:21:03.773  18727-18741/proximizer.ibeacon.adins.mobileque:my_process D/BluetoothAdapter﹕ startLeScan(): null
05-12 13:21:03.783  18727-18740/proximizer.ibeacon.adins.mobileque:my_process D/BluetoothAdapter﹕ onClientRegistered() - status=0 clientIf=5
05-12 13:21:08.803  18727-18741/proximizer.ibeacon.adins.mobileque:my_process D/BluetoothAdapter﹕ stopLeScan()
05-12 13:21:13.613  18619-18619/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerSetupReceiver_CheckingService_StatusRunning

=========================================================================
code below running after device unlock, it say region has been monitored buat startLeScan and stopLeScan not trigger again
=========================================================================

05-12 13:21:14.953  18619-18619/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerSetupReceiver_RefreshBluetooth_AlarmManagerSetEvery_20_Minute
05-12 13:21:14.973  18619-18619/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerSetupReceiver_CheckingService_AlarmManagerSetEvery_10_Second
05-12 13:21:19.973  18619-18619/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerSetupReceiver_CheckingService_StatusRunning
05-12 13:21:29.963  18619-18619/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerEventReceiver.onReceive() called
05-12 13:21:29.963  18727-18727/proximizer.ibeacon.adins.mobileque:my_process D/com.hascode.android.scheduler﹕ event received in service: Tue May 12 13:21:29 GMT+07:00 2015
05-12 13:21:29.973  18727-18727/proximizer.ibeacon.adins.mobileque:my_process I/EstimoteSDK﹕ com.estimote.sdk.BeaconManager.startMonitoring:403 Region already monitored but that's OK: Region{identifier=rid, proximityUUID=b9407f30-f5f8-466e-aff9-25556b57fe6d, major=null, minor=null}
05-12 13:21:29.973  18619-18619/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerSetupReceiver_CheckingService_StatusRunning
05-12 13:21:29.983  18727-18741/proximizer.ibeacon.adins.mobileque:my_process D/BluetoothAdapter﹕ startLeScan(): null
05-12 13:21:29.993  18727-18739/proximizer.ibeacon.adins.mobileque:my_process D/BluetoothAdapter﹕ onClientRegistered() - status=0 clientIf=5
05-12 13:21:39.963  18619-18619/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerSetupReceiver_CheckingService_StatusRunning
05-12 13:21:50.723  18619-18619/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerSetupReceiver_CheckingService_StatusRunning
05-12 13:22:06.723  18619-18619/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerSetupReceiver_CheckingService_StatusRunning

@ifvanagustrianto

Where do you declare your BeaconManager? In Activity/Application/Service?

@wiktor i’m declare in Service onStartCommand

@Override
public int onStartCommand(Intent intent, int flags, int startId) {

    Log.d(APP_TAG, "event received in service: " + new Date().toString());

    if (beaconManager == null) {
        beaconManager = new BeaconManager(this);
    }

    beaconManager.connect(new BeaconManager.ServiceReadyCallback() {
        @Override public void onServiceReady() {
            try {
                //Log.d(TAG, "serviceReady");
                beaconManager.startMonitoring(ALL_ESTIMOTE_BEACONS);
            } catch (RemoteException e) {
                //Log.e(TAG, "Cannot start ranging", e);
            }
        }
    });

    beaconManager.setBackgroundScanPeriod(5000,2000);

    beaconManager.setMonitoringListener(new BeaconManager.MonitoringListener() {
        @Override public void onEnteredRegion(Region region, List<Beacon> beacons) {
            //Log.d(TAG, "entered");
            Toast.makeText(SchedulerEventService.this, "Entered", Toast.LENGTH_LONG).show();

            Intent notificationIntent = new Intent(SchedulerEventService.this, MainActivity.class);
            notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                    | Intent.FLAG_ACTIVITY_SINGLE_TOP);
            PendingIntent intent = PendingIntent.getActivity(SchedulerEventService.this, 0,
                    notificationIntent, 0);

            Notification noti = new Notification.Builder(SchedulerEventService.this)
                    .setContentTitle("Entered")
                    .setContentText("You're home!")
                    .setSmallIcon(R.drawable.ic_launcher)
                    .setContentIntent(intent)
                    .build();

            NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            mNotificationManager.cancel(2);
            mNotificationManager.notify(1, noti);
        }
        @Override public void onExitedRegion(Region region) {
            //Log.d(TAG, "exited");
            Toast.makeText(SchedulerEventService.this, "Exited", Toast.LENGTH_LONG).show();
            NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            mNotificationManager.cancel(1);

            Notification noti = new Notification.Builder(SchedulerEventService.this)
                    .setContentTitle("Exited")
                    .setContentText("See you!")
                    .setSmallIcon(R.drawable.ic_launcher)
                    .build();

            mNotificationManager.notify(2, noti);
        }
    });

@ifvanagustrianto

I’m afraid that service is destroyed immediately after invoking onStartCommand. Could you override onDestroy method and check if it is invoked? (by debugging or logging)

BeaconManager itself starts a service so there is no need to start it within your service. Please do try initializing BeaconManager & start monitoring in your Application class.

@wiktor

my services is not destroy,
i’m already set onDestroy event too in my services, my code works fine if phone not sleep or lock, but when phone is locked/sleep, beaconmanager did’n scan bluetooth LE, but my service stil running,. (you can look my logcat if my service stil running “D/com.hascode.android﹕ SchedulerSetupReceiver_CheckingService_StatusRunning” )

@Override
public void onDestroy() {
    //Log.d(TAG, "Beacons monitoring service destroyed");
    //Toast.makeText(this, "Beacons monitoring service done", Toast.LENGTH_SHORT).show();
    Notification noti = new Notification.Builder(SchedulerEventService.this)
            .setContentTitle("Stopped")
            .setContentText("See you!")
            .setSmallIcon(R.drawable.ic_launcher)
            .build();
}

I’m already test if beaconManager startMonitoring in activity or application, it works when app in use but when app is killed/force close in task manager, beacon service is gone and cannot detect any beacon,… so i do it a little more tricky

what i want to do is creating long running Service, combine with alarmManager ( for refresh bluetooth, based on test that I’ve done if we monitoring/ranging for a long time without refresh. bluetooth will crash and phone must be restart), so it can always run monitoring even we don’t open the app.

i want explain first what i want to do, maybe someone have some problem with me…

i have four BroadcastReceiver

  • 1 for action Boot_Complete
  • 1 for action Package Added or Replace
    ( i separate into two broadcastreceiver because action bootcomplete and package cannot declare in same intent-filter [i dont know why :frowning: ] )

My BroadcastReceiver set two AlarmManager

  • 1 for startMonitoring again every 20 minute ( because if start monitoring for a long time, bluetooth will crash )
    for the first time install/booting and every 20 minute, Receiver will call another BroadcastReceiver(ScheduleEventReceiver), which will run my service ( SchedulerEventService )

  • 1 for checking my service is stil running or not.
    every 10 second, alarmmanager will call ScheduleResumeReceiver which will check my service status run or not, if not run, ScheduleResumeReceiver will run my service again (SchedulerEventService)

all estimote beaconManager is placed in SchedulerEventService, inside onStartCommand

Thanks in advance :smile:

1/ Can you turn on debug logging of the SDK? That is EstimoteSDK.enableDebugLogging(true);. SDK will produce more more logs so I can investigate more.

2/ Why Bluetooth is crashing? Any ideas? That’s very bad. On which OS/device you are testing?

3/ From what I see you do not need monitoring as you are implementing it by yourself. All you need is ranging (startRanging method) executed every 20s (and that’s more less what monitoring is).

  1. Ok sir, i will inform you later for more logs,

  2. i don’t have any idea why bluetoothAdapter crashing, in Estimote Demos(github) have an activity which is startRanging for finding Beacons, if i stay in that activity for a some time ( depend on scanPeriodTime and waitPeriodTime ) Bluetooth adapter will crash, and estimote SDK will produce log “Cannot start Bluetooth LEScan”. Bluetooth in my smartphone can’t be on or off again so i must restart my phone.
    I’m Testing in Android 4.4.4 Lenovo A6000

  3. As I read Ranging is recomended for foreground activity ( like Estimote ExampleApps in GooglePlay ) using proximity range for identify a area of product.

I only need Monitoring for give Notification when user entered Region of a Beacon so user will open my App, and give feedback when exited Region (onExitRegion)
can you give me recomended scanTime and waitTime for Monitoring and Ranging ?

LOG BELOW PRODUCE WHEN MY APP INSTALLED

05-13 09:40:33.049    4763-4763/proximizer.ibeacon.adins.mobileque D/OpenGLRenderer﹕ Enabling debug mode 0
    05-13 09:40:33.119    4763-4763/proximizer.ibeacon.adins.mobileque I/Timeline﹕ Timeline: Activity_idle id: android.os.BinderProxy@41917e80 time:2083659
    05-13 09:40:33.519    4763-4763/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerSetupReceiver_RefreshBluetooth_AlarmManagerSetEvery_20_Minute
    05-13 09:40:33.519    4763-4763/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerSetupReceiver_CheckingService_AlarmManagerSetEvery_10_Second
    05-13 09:40:38.529    4763-4763/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerSetupReceiver_CheckingService_StatusStopped
    05-13 09:40:38.559    4763-4763/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerSetupReceiver_CheckingService_StatusRestarted
    05-13 09:40:38.569    4862-4862/proximizer.ibeacon.adins.mobileque:my_process D/ActivityThread﹕ handleBindApplication:proximizer.ibeacon.adins.mobileque:my_process
    05-13 09:40:38.569    4862-4862/proximizer.ibeacon.adins.mobileque:my_process D/ActivityThread﹕ setTargetHeapUtilization:0.75
    05-13 09:40:38.569    4862-4862/proximizer.ibeacon.adins.mobileque:my_process D/ActivityThread﹕ setTargetHeapMinFree:524288
    05-13 09:40:38.579    4862-4862/proximizer.ibeacon.adins.mobileque:my_process D/com.hascode.android.scheduler﹕ event received in service: Wed May 13 09:40:38 GMT+07:00 2015
    05-13 09:40:38.589    4862-4862/proximizer.ibeacon.adins.mobileque:my_process I/EstimoteSDK﹕ com.estimote.sdk.service.BeaconService.onCreate:186 Creating service
    05-13 09:40:38.599    4862-4875/proximizer.ibeacon.adins.mobileque:my_process D/EstimoteSDK﹕ com.estimote.sdk.service.BeaconService$IncomingHandler$1.run:499 Setting background scan period: ScanPeriodData{scanPeriodMillis=5000, waitTimeMillis=5000}
    05-13 09:40:38.599    4862-4875/proximizer.ibeacon.adins.mobileque:my_process V/EstimoteSDK﹕ com.estimote.sdk.service.BeaconService.startMonitoring:256 Starting monitoring: Region{identifier=rid, proximityUUID=b9407f30-f5f8-466e-aff9-25556b57fe6d, major=null, minor=null}
    05-13 09:40:38.599    4862-4875/proximizer.ibeacon.adins.mobileque:my_process D/BluetoothAdapter﹕ startLeScan(): null
    05-13 09:40:38.639    4862-4873/proximizer.ibeacon.adins.mobileque:my_process D/BluetoothAdapter﹕ onClientRegistered() - status=0 clientIf=5
    05-13 09:40:41.649    4862-4873/proximizer.ibeacon.adins.mobileque:my_process V/EstimoteSDK﹕ com.estimote.sdk.service.BeaconService$InternalLeScanCallback.onLeScan:522 Device 88:0F:10:54:A8:E8 is not an Estimote beacon
    05-13 09:40:43.649    4862-4875/proximizer.ibeacon.adins.mobileque:my_process D/BluetoothAdapter﹕ stopLeScan()
    05-13 09:40:48.699    4763-4763/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerEventReceiver.onReceive() called
    05-13 09:40:48.709    4862-4862/proximizer.ibeacon.adins.mobileque:my_process D/com.hascode.android.scheduler﹕ event received in service: Wed May 13 09:40:48 GMT+07:00 2015
    05-13 09:40:48.709    4763-4763/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerSetupReceiver_CheckingService_StatusRunning
    05-13 09:40:48.709    4862-4862/proximizer.ibeacon.adins.mobileque:my_process I/EstimoteSDK﹕ com.estimote.sdk.BeaconManager.startMonitoring:403 Region already monitored but that's OK: Region{identifier=rid, proximityUUID=b9407f30-f5f8-466e-aff9-25556b57fe6d, major=null, minor=null}
    05-13 09:40:48.729    4862-4875/proximizer.ibeacon.adins.mobileque:my_process D/BluetoothAdapter﹕ startLeScan(): null
    05-13 09:40:48.739    4862-4874/proximizer.ibeacon.adins.mobileque:my_process D/BluetoothAdapter﹕ onClientRegistered() - status=0 clientIf=5
    05-13 09:40:48.739    4862-4875/proximizer.ibeacon.adins.mobileque:my_process V/EstimoteSDK﹕ com.estimote.sdk.service.BeaconService.startMonitoring:256 Starting monitoring: Region{identifier=rid, proximityUUID=b9407f30-f5f8-466e-aff9-25556b57fe6d, major=null, minor=null}
    05-13 09:40:48.739    4862-4875/proximizer.ibeacon.adins.mobileque:my_process D/EstimoteSDK﹕ com.estimote.sdk.service.BeaconService.startScanning:281 Scanning already in progress, not starting one more
    05-13 09:40:48.749    4862-4875/proximizer.ibeacon.adins.mobileque:my_process D/EstimoteSDK﹕ com.estimote.sdk.service.BeaconService$IncomingHandler$1.run:499 Setting background scan period: ScanPeriodData{scanPeriodMillis=5000, waitTimeMillis=5000}
    05-13 09:40:50.669    4862-4874/proximizer.ibeacon.adins.mobileque:my_process V/EstimoteSDK﹕ com.estimote.sdk.service.BeaconService$InternalLeScanCallback.onLeScan:522 Device 88:0F:10:54:A8:E8 is not an Estimote beacon
    05-13 09:40:53.739    4862-4875/proximizer.ibeacon.adins.mobileque:my_process D/BluetoothAdapter﹕ stopLeScan()
    05-13 09:40:58.789    4763-4763/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerSetupReceiver_CheckingService_StatusRunning
    05-13 09:40:58.789    4862-4875/proximizer.ibeacon.adins.mobileque:my_process D/BluetoothAdapter﹕ startLeScan(): null
    05-13 09:40:58.799    4862-4873/proximizer.ibeacon.adins.mobileque:my_process D/BluetoothAdapter﹕ onClientRegistered() - status=0 clientIf=5
    05-13 09:41:03.799    4862-4875/proximizer.ibeacon.adins.mobileque:my_process D/BluetoothAdapter﹕ stopLeScan()
    05-13 09:41:08.829    4862-4875/proximizer.ibeacon.adins.mobileque:my_process D/BluetoothAdapter﹕ startLeScan(): null
    05-13 09:41:08.829    4862-4873/proximizer.ibeacon.adins.mobileque:my_process D/BluetoothAdapter﹕ onClientRegistered() - status=0 clientIf=5
    05-13 09:41:08.829    4763-4763/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerSetupReceiver_CheckingService_StatusRunning

LOG BELOW PRODUCE WHEN MY PHONE LOCK

05-13 09:41:08.829    4763-4763/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerSetupReceiver_CheckingService_StatusRunning
05-13 09:41:18.529    4763-4763/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerSetupReceiver_CheckingService_StatusRunning
05-13 09:41:20.339    4862-4873/proximizer.ibeacon.adins.mobileque:my_process V/EstimoteSDK﹕ com.estimote.sdk.service.BeaconService$InternalLeScanCallback.onLeScan:522 Device 88:0F:10:54:A8:E8 is not an Estimote beacon
05-13 09:41:28.529    4763-4763/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerSetupReceiver_CheckingService_StatusRunning
05-13 09:41:38.609    4763-4763/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerSetupReceiver_CheckingService_StatusRunning
05-13 09:41:48.529    4763-4763/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerSetupReceiver_CheckingService_StatusRunning
05-13 09:41:58.529    4763-4763/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerSetupReceiver_CheckingService_StatusRunning
05-13 09:42:08.529    4763-4763/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerSetupReceiver_CheckingService_StatusRunning
05-13 09:42:18.529    4763-4763/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerSetupReceiver_CheckingService_StatusRunning
05-13 09:42:28.529    4763-4763/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerSetupReceiver_CheckingService_StatusRunning
05-13 09:42:38.529    4763-4763/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerSetupReceiver_CheckingService_StatusRunning

LOG BELOW PRODUCE WHEN I’M UNLOCK MY PHONE

05-13 09:42:45.919    4763-4763/proximizer.ibeacon.adins.mobileque I/Timeline﹕ Timeline: Activity_idle id: android.os.BinderProxy@41917e80 time:2216457
05-13 09:42:46.039    4763-4763/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerSetupReceiver_RefreshBluetooth_AlarmManagerSetEvery_20_Minute
05-13 09:42:46.049    4763-4763/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerSetupReceiver_CheckingService_AlarmManagerSetEvery_10_Second
05-13 09:42:51.049    4763-4763/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerSetupReceiver_CheckingService_StatusRunning
05-13 09:43:08.149    4763-4763/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerEventReceiver.onReceive() called
05-13 09:43:08.149    4862-4862/proximizer.ibeacon.adins.mobileque:my_process D/com.hascode.android.scheduler﹕ event received in service: Wed May 13 09:43:08 GMT+07:00 2015
05-13 09:43:08.159    4763-4763/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerSetupReceiver_CheckingService_StatusRunning
05-13 09:43:08.159    4862-4862/proximizer.ibeacon.adins.mobileque:my_process I/EstimoteSDK﹕ com.estimote.sdk.BeaconManager.startMonitoring:403 Region already monitored but that's OK: Region{identifier=rid, proximityUUID=b9407f30-f5f8-466e-aff9-25556b57fe6d, major=null, minor=null}
05-13 09:43:08.169    4862-4875/proximizer.ibeacon.adins.mobileque:my_process V/EstimoteSDK﹕ com.estimote.sdk.service.BeaconService.startMonitoring:256 Starting monitoring: Region{identifier=rid, proximityUUID=b9407f30-f5f8-466e-aff9-25556b57fe6d, major=null, minor=null}
05-13 09:43:08.169    4862-4875/proximizer.ibeacon.adins.mobileque:my_process D/EstimoteSDK﹕ com.estimote.sdk.service.BeaconService.startScanning:281 Scanning already in progress, not starting one more
05-13 09:43:08.169    4862-4875/proximizer.ibeacon.adins.mobileque:my_process D/EstimoteSDK﹕ com.estimote.sdk.service.BeaconService$IncomingHandler$1.run:499 Setting background scan period: ScanPeriodData{scanPeriodMillis=5000, waitTimeMillis=5000}
05-13 09:43:11.049    4763-4763/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerSetupReceiver_CheckingService_StatusRunning
05-13 09:43:21.049    4763-4763/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerSetupReceiver_CheckingService_StatusRunning
05-13 09:43:31.049    4763-4763/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerSetupReceiver_CheckingService_StatusRunning
05-13 09:43:41.049    4763-4763/proximizer.ibeacon.adins.mobileque D/com.hascode.android﹕ SchedulerSetupReceiver_CheckingService_StatusRunning

As you can see when phone locked, only alarmManager runs a BroadcastReceiver for check if my service Running or not and my services stil running ( not destroyed )

When my phone unlock again, it trigger to re-run service so the Logs produce

05-13 09:43:08.159    4862-4862/proximizer.ibeacon.adins.mobileque:my_process I/EstimoteSDK﹕ com.estimote.sdk.BeaconManager.startMonitoring:403 Region already monitored but that's OK: Region{identifier=rid, proximityUUID=b9407f30-f5f8-466e-aff9-25556b57fe6d, major=null, minor=null}
05-13 09:43:08.169    4862-4875/proximizer.ibeacon.adins.mobileque:my_process V/EstimoteSDK﹕ com.estimote.sdk.service.BeaconService.startMonitoring:256 Starting monitoring: Region{identifier=rid, proximityUUID=b9407f30-f5f8-466e-aff9-25556b57fe6d, major=null, minor=null}
05-13 09:43:08.169    4862-4875/proximizer.ibeacon.adins.mobileque:my_process D/EstimoteSDK﹕ com.estimote.sdk.service.BeaconService.startScanning:281 Scanning already in progress, not starting one more

but i can’t see startLeScan(), onClientRegistered(), stopLeScan() again in Logs.

Two things that caught my attention:

1/ In logs there is V/EstimoteSDK﹕ com.estimote.sdk.service.BeaconService$InternalLeScanCallback.onLeScan:522 Device 88:0F:10:54:A8:E8 is not an Estimote beacon: are you using Estimote beacons?

2/ Please configure and initialize BeaconManager only once in onStartCommand (setting listeners, starting monitoring, connecting to it).

One additional question: does BeaconManager works for you outside of service? (like in activity?)

  1. I don’t know why this log show up, because when i scan Beacons in activity, i just found 3 beacons ( 1 set of estimote ).

  2. i’m already setting once in onStartCommand ( see my onStartCommand code in the post 3 days ago ), but my service can be called more than once so onStartCommand will call more than once too. is this problem ?

BeaconManager works fine in activity like an example in EstimoteSDKDemo,


lets forget about my service for a while,
i’m tested with EstimoteSDK Example, when i open ListBeaconActivity it will start scanning every x seconds. and produce log Estimote Beacon detail ? in ListBeaconActivity i’m comment all stopRanging code so it will always scanning if i’m stay in ListBeaconActivity. when app in Background it stil produce log (so it’s mean in the background estimote stil scanning)

Log produce when i’m open ListBeaconActivity and minimize app

05-15 09:34:33.498    3467-3478/com.estimote.examples.demos I/BeaconService﹕ ========================
05-15 09:34:33.498    3467-3478/com.estimote.examples.demos I/BeaconService﹕ found beacon: 1
05-15 09:34:33.498    3467-3478/com.estimote.examples.demos I/BeaconService﹕ C6:E5:8D:0E:CD:24
05-15 09:34:35.088    3467-3795/com.estimote.examples.demos D/BeaconService﹕ Beacon Beacon [proximityUUID=b9407f30-f5f8-466e-aff9-25556b57fe6d, name=estimote, macAddress=F2:55:2C:A1:FB:67, major=3, minor=1, measuredPower=-60, rssi=-53]
05-15 09:34:35.088    3467-3795/com.estimote.examples.demos D/BeaconService﹕ Beacon name: estimote
05-15 09:34:35.088    3467-3795/com.estimote.examples.demos D/BeaconService﹕ b9407f30-f5f8-466e-aff9-25556b57fe6d
05-15 09:34:35.088    3467-3795/com.estimote.examples.demos I/BeaconService﹕ ========================
05-15 09:34:35.088    3467-3795/com.estimote.examples.demos I/BeaconService﹕ found beacon: 2
05-15 09:34:35.088    3467-3795/com.estimote.examples.demos I/BeaconService﹕ C6:E5:8D:0E:CD:24
05-15 09:34:35.088    3467-3795/com.estimote.examples.demos I/BeaconService﹕ F2:55:2C:A1:FB:67
05-15 09:34:35.458    3467-3479/com.estimote.examples.demos D/BeaconService﹕ Beacon Beacon [proximityUUID=b9407f30-f5f8-466e-aff9-25556b57fe6d, name=estimote, macAddress=C9:4E:B4:A7:8F:14, major=1, minor=1, measuredPower=-60, rssi=-54]
05-15 09:34:35.458    3467-3479/com.estimote.examples.demos D/BeaconService﹕ Beacon name: estimote
05-15 09:34:35.458    3467-3479/com.estimote.examples.demos D/BeaconService﹕ b9407f30-f5f8-466e-aff9-25556b57fe6d
05-15 09:34:35.458    3467-3479/com.estimote.examples.demos I/BeaconService﹕ ========================
05-15 09:34:35.458    3467-3479/com.estimote.examples.demos I/BeaconService﹕ found beacon: 3
05-15 09:34:35.458    3467-3479/com.estimote.examples.demos I/BeaconService﹕ C9:4E:B4:A7:8F:14
05-15 09:34:35.458    3467-3479/com.estimote.examples.demos I/BeaconService﹕ C6:E5:8D:0E:CD:24
05-15 09:34:35.458    3467-3479/com.estimote.examples.demos I/BeaconService﹕ F2:55:2C:A1:FB:67
05-15 09:34:43.508    3467-3797/com.estimote.examples.demos D/BluetoothAdapter﹕ stopLeScan()
05-15 09:34:53.548    3467-3797/com.estimote.examples.demos D/BluetoothAdapter﹕ stopLeScan()
05-15 09:34:53.598    3467-3797/com.estimote.examples.demos D/BluetoothAdapter﹕ startLeScan(): null
05-15 09:34:53.608    3467-3478/com.estimote.examples.demos D/BluetoothAdapter﹕ onClientRegistered() - status=0 clientIf=5
05-15 09:34:53.648    3467-3479/com.estimote.examples.demos D/BeaconService﹕ Beacon Beacon [proximityUUID=b9407f30-f5f8-466e-aff9-25556b57fe6d, name=estimote, macAddress=C9:4E:B4:A7:8F:14, major=1, minor=1, measuredPower=-60, rssi=-50]
05-15 09:34:53.648    3467-3479/com.estimote.examples.demos D/BeaconService﹕ Beacon name: estimote
05-15 09:34:53.648    3467-3479/com.estimote.examples.demos D/BeaconService﹕ b9407f30-f5f8-466e-aff9-25556b57fe6d
05-15 09:34:53.648    3467-3479/com.estimote.examples.demos I/BeaconService﹕ ========================

But when i’m locked my phone, Log not produce any result of Beacons,
it will produce log like this

05-15 09:39:15.458    3467-3797/com.estimote.examples.demos D/BluetoothAdapter﹕ stopLeScan()
05-15 09:39:25.458    3467-3797/com.estimote.examples.demos D/BluetoothAdapter﹕ stopLeScan()
05-15 09:39:39.188    3467-3797/com.estimote.examples.demos D/BluetoothAdapter﹕ stopLeScan()
05-15 09:39:45.458    3467-3797/com.estimote.examples.demos D/BluetoothAdapter﹕ stopLeScan()
05-15 09:39:55.458    3467-3797/com.estimote.examples.demos D/BluetoothAdapter﹕ stopLeScan()
05-15 09:40:05.458    3467-3797/com.estimote.examples.demos D/BluetoothAdapter﹕ stopLeScan()
05-15 09:40:15.458    3467-3797/com.estimote.examples.demos D/BluetoothAdapter﹕ stopLeScan()
05-15 09:40:25.458    3467-3797/com.estimote.examples.demos D/BluetoothAdapter﹕ stopLeScan()
05-15 09:40:25.458    3467-3797/com.estimote.examples.demos V/RangingRegion﹕ Not seen lately: Beacon [proximityUUID=03094d49-1eff-5701-001c-a128824eeefb, name=MI, macAddress=88:0F:10:56:87:2E, major=3584, minor=136, measuredPower=15, rssi=-100]
05-15 09:40:25.458    3467-3797/com.estimote.examples.demos V/RangingRegion﹕ Not seen lately: Beacon [proximityUUID=03094d49-1eff-5701-001c-a128824eeefb, name=MI, macAddress=88:0F:10:56:87:2E, major=3584, minor=136, measuredPower=15, rssi=-100]
05-15 09:40:35.458    3467-3797/com.estimote.examples.demos D/BluetoothAdapter﹕ stopLeScan()
05-15 09:40:45.458    3467-3797/com.estimote.examples.demos D/BluetoothAdapter﹕ stopLeScan()
05-15 09:40:55.458    3467-3797/com.estimote.examples.demos D/BluetoothAdapter﹕ stopLeScan()
05-15 09:41:05.458    3467-3797/com.estimote.examples.demos D/BluetoothAdapter﹕ stopLeScan()
05-15 09:41:05.458    3467-3797/com.estimote.examples.demos V/RangingRegion﹕ Not seen lately: Beacon [proximityUUID=b9407f30-f5f8-466e-aff9-25556b57fe6d, name=estimote, macAddress=C9:4E:B4:A7:8F:14, major=1, minor=1, measuredPower=-60, rssi=-54]
05-15 09:41:05.458    3467-3797/com.estimote.examples.demos V/RangingRegion﹕ Not seen lately: Beacon [proximityUUID=b9407f30-f5f8-466e-aff9-25556b57fe6d, name=estimote, macAddress=C6:E5:8D:0E:CD:24, major=2, minor=1, measuredPower=-60, rssi=-48]
05-15 09:41:05.458    3467-3797/com.estimote.examples.demos V/RangingRegion﹕ Not seen lately: Beacon [proximityUUID=b9407f30-f5f8-466e-aff9-25556b57fe6d, name=estimote, macAddress=F2:55:2C:A1:FB:67, major=3, minor=1, measuredPower=-60, rssi=-64]
05-15 09:41:05.458    3467-3797/com.estimote.examples.demos V/RangingRegion﹕ Not seen lately: Beacon [proximityUUID=b9407f30-f5f8-466e-aff9-25556b57fe6d, name=estimote, macAddress=C9:4E:B4:A7:8F:14, major=1, minor=1, measuredPower=-60, rssi=-54]
05-15 09:41:05.458    3467-3797/com.estimote.examples.demos V/RangingRegion﹕ Not seen lately: Beacon [proximityUUID=b9407f30-f5f8-466e-aff9-25556b57fe6d, name=estimote, macAddress=C6:E5:8D:0E:CD:24, major=2, minor=1, measuredPower=-60, rssi=-48]
05-15 09:41:05.458    3467-3797/com.estimote.examples.demos V/RangingRegion﹕ Not seen lately: Beacon [proximityUUID=b9407f30-f5f8-466e-aff9-25556b57fe6d, name=estimote, macAddress=F2:55:2C:A1:FB:67, major=3, minor=1, measuredPower=-60, rssi=-64]
05-15 09:41:15.938    3467-3797/com.estimote.examples.demos D/BluetoothAdapter﹕ stopLeScan()
05-15 09:41:30.948    3467-3797/com.estimote.examples.demos D/BluetoothAdapter﹕ stopLeScan()
05-15 09:41:35.468    3467-3797/com.estimote.examples.demos D/BluetoothAdapter﹕ stopLeScan()
05-15 09:41:45.458    3467-3797/com.estimote.examples.demos D/BluetoothAdapter﹕ stopLeScan()
05-15 09:41:55.458    3467-3797/com.estimote.examples.demos D/BluetoothAdapter﹕ stopLeScan()
05-15 09:42:05.458    3467-3797/com.estimote.examples.demos D/BluetoothAdapter﹕ stopLeScan()
05-15 09:42:15.938    3467-3797/com.estimote.examples.demos D/BluetoothAdapter﹕ stopLeScan()
05-15 09:42:25.458    3467-3797/com.estimote.examples.demos D/BluetoothAdapter﹕ stopLeScan()
05-15 09:42:35.458    3467-3797/com.estimote.examples.demos D/BluetoothAdapter﹕ stopLeScan()

re 2/ Yes, onStartCommand can be invoked many times but you should not try to configure BeaconManager each time.

I’m still thinking about it. When phone is locked, it goes in “deep sleep” and some background tasks can be throttled. BeaconManager (and thus BeaconService) are protected from it.

  1. what do you mean about configure BeaconManager, is like beaconManager.connect, setBackgroundPeriod and setMonitoringListener ?
    is there any method to check if beaconManager is already configured or not ? beause i don’t get your message 'bout not to try configure beaconManager each time :smile: ( because i don’t know how to check it )

  2. so the conclusion is BeaconService is stopped by OS when it turn into deep sleep ? and Monitoring is not working when phone is locked ? :frowning:

Thanks in advance

1/ yes 2/ yes for some reason

I’d recommend to approaches:
1/ Do not use service and use BeaconManager in your Application class. Resolve this Bluetooth crashing.
2/ Use your service. In every onStartCommand start ranging and after 10s stop ranging.

  1. Bluetooth stil crashing even BeaconManager is placed in Application/activity… ( only crash after x minute depends on scanPeriodTime and waitPeriodTime )

  2. Ok i will test it.

I hope beaconServices can run in background even if phone sleep / app closed etc :blush: in the next update. Because user doesn’t always hold their phone it their hand, so we ( as developer ) must notice the user for look their phone if entered area of beacons :smile:

Thanks for your support wiktor,…

Hi wiktor, i’m already tested implement your suggestion in my code…

you suggest to startMonitoring/Ranging and after x second stopMonitoring/Ranging.

now i’m move my code from onStartCommand to onCreate so it will run once when Service is created or recreate. and now i’m using schedule threading for handle StartStopMonitoring.

you can check my code here.

but the problem is, when beaconmanager.connect and startMonitoring/ranging for a next time / next loop, method onEntered is fired again and again… so if i put Notification in onEntered method, it will produce Notification every x second…

Thanks,
Regrads,
Ifvan

Hi Wiktor,

I’m just want to inform you maybe it will help,
I’m tested implement scanLeDevice from http://developer.android.com/samples/BluetoothLeGatt/index.html to my service to prove if Bluetooth background process is killed or not when turn into deep sleep mode.

and what i found is scanLeDevice stil running whenever phone is Locked and can stil produce Log device(devicename and deviceaddress), so i think there is something wrong with estimote sdk

There is my tested code for scanningLe in services

and this is the log produced from that code at any phone state ( on / locked )

05-22 10:13:56.038    6347-6360/proximizer.ibeacon.adins.mobileque:my_process D/com.hascode.android.scheduler﹕ Call beacon Scan
05-22 10:13:56.038    6347-6360/proximizer.ibeacon.adins.mobileque:my_process D/BluetoothAdapter﹕ startLeScan(): null
05-22 10:13:56.038    6347-6359/proximizer.ibeacon.adins.mobileque:my_process D/BluetoothAdapter﹕ onClientRegistered() - status=0 clientIf=5
05-22 10:13:57.028    6347-6347/proximizer.ibeacon.adins.mobileque:my_process D/Device Found﹕ Device : estimote
05-22 10:13:57.028    6347-6347/proximizer.ibeacon.adins.mobileque:my_process D/Device Found﹕ Device : C6:E5:8D:0E:CD:24
05-22 10:13:58.158    6347-6347/proximizer.ibeacon.adins.mobileque:my_process D/Device Found﹕ Device : estimote
05-22 10:13:58.158    6347-6347/proximizer.ibeacon.adins.mobileque:my_process D/Device Found﹕ Device : F2:55:2C:A1:FB:67
05-22 10:13:58.448    6347-6347/proximizer.ibeacon.adins.mobileque:my_process D/Device Found﹕ Device : estimote
05-22 10:13:58.448    6347-6347/proximizer.ibeacon.adins.mobileque:my_process D/Device Found﹕ Device : C9:4E:B4:A7:8F:14
05-22 10:14:01.798    6347-6347/proximizer.ibeacon.adins.mobileque:my_process D/Device Found﹕ Device : MI
05-22 10:14:01.798    6347-6347/proximizer.ibeacon.adins.mobileque:my_process D/Device Found﹕ Device : 88:0F:10:54:A8:E8
05-22 10:14:06.038    6347-6347/proximizer.ibeacon.adins.mobileque:my_process D/BluetoothAdapter﹕ stopLeScan()
05-22 10:14:31.038    6347-6360/proximizer.ibeacon.adins.mobileque:my_process D/com.hascode.android.scheduler﹕ Call beacon Scan
05-22 10:14:31.038    6347-6360/proximizer.ibeacon.adins.mobileque:my_process D/BluetoothAdapter﹕ startLeScan(): null
05-22 10:14:31.048    6347-6358/proximizer.ibeacon.adins.mobileque:my_process D/BluetoothAdapter﹕ onClientRegistered() - status=0 clientIf=5
05-22 10:14:32.088    6347-6347/proximizer.ibeacon.adins.mobileque:my_process D/Device Found﹕ Device : estimote
05-22 10:14:32.088    6347-6347/proximizer.ibeacon.adins.mobileque:my_process D/Device Found﹕ Device : F2:55:2C:A1:FB:67
05-22 10:14:33.018    6347-6347/proximizer.ibeacon.adins.mobileque:my_process D/Device Found﹕ Device : estimote
05-22 10:14:33.028    6347-6347/proximizer.ibeacon.adins.mobileque:my_process D/Device Found﹕ Device : C6:E5:8D:0E:CD:24
05-22 10:14:34.468    6347-6347/proximizer.ibeacon.adins.mobileque:my_process D/Device Found﹕ Device : estimote
05-22 10:14:34.468    6347-6347/proximizer.ibeacon.adins.mobileque:my_process D/Device Found﹕ Device : C9:4E:B4:A7:8F:14
05-22 10:14:40.308    6347-6347/proximizer.ibeacon.adins.mobileque:my_process D/Device Found﹕ Device : MI
05-22 10:14:40.308    6347-6347/proximizer.ibeacon.adins.mobileque:my_process D/Device Found﹕ Device : 88:0F:10:54:A8:E8
05-22 10:14:41.038    6347-6347/proximizer.ibeacon.adins.mobileque:my_process D/BluetoothAdapter﹕ stopLeScan()
05-22 10:15:06.038    6347-6360/proximizer.ibeacon.adins.mobileque:my_process D/com.hascode.android.scheduler﹕ Call beacon Scan
05-22 10:15:06.038    6347-6360/proximizer.ibeacon.adins.mobileque:my_process D/BluetoothAdapter﹕ startLeScan(): null
05-22 10:15:06.038    6347-6359/proximizer.ibeacon.adins.mobileque:my_process D/BluetoothAdapter﹕ onClientRegistered() - status=0 clientIf=5
05-22 10:15:07.028    6347-6347/proximizer.ibeacon.adins.mobileque:my_process D/Device Found﹕ Device : estimote
05-22 10:15:07.028    6347-6347/proximizer.ibeacon.adins.mobileque:my_process D/Device Found﹕ Device : C6:E5:8D:0E:CD:24
05-22 10:15:08.098    6347-6347/proximizer.ibeacon.adins.mobileque:my_process D/Device Found﹕ Device : estimote
05-22 10:15:08.098    6347-6347/proximizer.ibeacon.adins.mobileque:my_process D/Device Found﹕ Device : F2:55:2C:A1:FB:67
05-22 10:15:08.388    6347-6347/proximizer.ibeacon.adins.mobileque:my_process D/Device Found﹕ Device : estimote
05-22 10:15:08.388    6347-6347/proximizer.ibeacon.adins.mobileque:my_process D/Device Found﹕ Device : C9:4E:B4:A7:8F:14
05-22 10:15:16.048    6347-6347/proximizer.ibeacon.adins.mobileque:my_process D/BluetoothAdapter﹕ stopLeScan()

ifvanagustrianto, Wiktor any further movement on this ? We are noticing on some devices the monitoring stops after a few hours ie we stop getting push notifications that we have implemented. it happens when the phone has been sleeping for over an hour.

I have the same issue, why this subject is never solved?