package com.mobstac.beaconstacdemo;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class NearbyBeaconBroadcastReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d(NearbyBeaconBroadcastReceiver.class.getName(), "Beacons found in background");
    }

}

@@ -30,16 +30,41 @@
 cdemo;%0A%0A
+import android.Manifest;%0A
 import a
@@ -179,16 +179,542 @@
 oid.
-util.Log
+content.pm.PackageManager;%0Aimport android.os.Handler;%0Aimport android.support.v4.app.ActivityCompat;%0Aimport android.util.Log;%0A%0Aimport com.google.android.gms.nearby.Nearby;%0Aimport com.google.android.gms.nearby.messages.Message;%0Aimport com.google.android.gms.nearby.messages.MessageListener;%0Aimport com.mobstac.beaconstac.Beaconstac;%0Aimport com.mobstac.beaconstac.core.MSException;%0Aimport com.mobstac.beaconstac.interfaces.MSErrorListener;%0Aimport com.mobstac.beaconstac.interfaces.MSSyncListener;%0Aimport com.mobstac.beaconstac.utils.Util
 ;%0A%0Ap
@@ -784,16 +784,51 @@
 iver %7B%0A%0A
+    Beaconstac beaconstac = null;%0A%0A
     @Ove
@@ -859,16 +859,22 @@
 Receive(
+final 
 Context 
@@ -911,98 +911,2334 @@
     
-Log.d(NearbyBeaconBroadcastReceiver.class.getName(), %22Beacons found in
+if (Util.isAppIsInBackground(context.getApplicationContext())) %7B%0A            Nearby.getMessagesClient(context).handleIntent(intent, new MessageListener() %7B%0A                @Override%0A                public void onFound(Message message) %7B%0A                    try %7B%0A                        if (ActivityCompat.checkSelfPermission(context.getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED %7C%7C ActivityCompat.checkSelfPermission(context.getApplicationContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) %7B%0A                            return;%0A                        %7D%0A                        beaconstac = Beaconstac.initialize(context.getApplicationContext(), %22MY_DEVELOPER_TOKEN%22, new MSSyncListener() %7B%0A                            @Override%0A                            public void onSuccess() %7B%0A                                beaconstac.startScanningBeacons(new MSErrorListener() %7B%0A                                    @Override%0A                                    public void onError(MSException msException) %7B%0A%0A                                    %7D%0A                                %7D);%0A                            %7D%0A%0A                            @Override%0A                            public void onFailure(MSException msException) %7B%0A%0A                            %7D%0A                        %7D);%0A                    %7D catch (MSException e) %7B%0A                        e.printStackTrace();%0A                    %7D%0A                    if (beaconstac != null) %7B%0A                        Handler handler = new Handler();%0A                        handler.postDelayed(new Runnable() %7B%0A                            @Override%0A                            public void run() %7B%0A                               
  b
+e
 ac
-kground%22);%0A
+onstac.stopScanningBeacons(new MSErrorListener() %7B%0A                                    @Override%0A                                    public void onError(MSException msException) %7B%0A%0A                                    %7D%0A                                %7D);%0A                            %7D%0A                        %7D, 10000); // Set the duration for which the scan needs to run for.%0A                    %7D%0A                %7D%0A%0A                @Override%0A                public void onLost(Message message) %7B%0A                %7D%0A            %7D);%0A    
     %7D%0A
+    %7D
 %0A%7D%0A

Add backgroung scanning example to NearbyBeaconBroadcastReceiver