Search code examples
ibeaconibeacon-android

How can I test the background scan and launch the application in background with iBeacon-Android?


I am using the pro library.
But I just found doc for free library I cannot find any doc for pro version.

Also, I don't know how to implement the background mode even using the pro sample.

Here are the steps:

  1. Build the pro sample project
  2. start the iBeacon source(using iPad) and it can be detected
  3. start the application and then press home button the make it in background
  4. Turn off the iBeacon source
  5. Turn on the iBeacon source
  6. However, more than 5 minutes, the application does not launch

So, can anyone verify the step I did?
How can I test the background mode more easily?

Also, for the BootstrapNotifier, is it just work only first time when the device reboot?
After that, even I put application in background, the application will not launch when it detect iBeacon?


Solution

  • Your testing method sounds fine. I think the issue is that the reference app for the pro library only auto launches the app on the first detection after boot. After that, it sends a notification instead, and tapping on that notification launches the app.

    This is purely for demonstration purposes. You can change it to auto launch on every detection if you wish. Simply alter the haveDetectedIBeaconsSinceBoot logic in this code:

    @Override
    public void didEnterRegion(Region arg0) {
        // In this example, this class sends a notification to the user whenever an iBeacon
        // matching a Region (defined above) are first seen.
        Log.d(TAG, "did enter region.");
        if (!haveDetectedIBeaconsSinceBoot) {
            Log.d(TAG, "auto launching MainActivity");
    
            // The very first time since boot that we detect an iBeacon, we launch the
            // MainActivity
            Intent intent = new Intent(this, MainActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            // Important:  make sure to add android:launchMode="singleInstance" in the manifest
            // to keep multiple copies of this activity from getting created if the user has
            // already manually launched the app.
            this.startActivity(intent);
            haveDetectedIBeaconsSinceBoot = true;
        } else {
            // If we have already seen iBeacons and launched the MainActivity before, we simply
            // send a notification to the user on subsequent detections.
            Log.d(TAG, "Sending notification.");
            sendNotification();
        }
    
    
    }
    

    The javadoc link was missing from the main documentation page when you posted this question. That is fixed now.