title: Beacons not detected in Android service
body: <p>I'm using the Altbeacon library (stable release 2.1.4) to detect beacons. If I do it in an Activity, I have no problems detecting them. However I can't get this to work from a service. Here's what I've got:</p>
  
  <pre><code>package com.ibeacontest.android;
  
  
  import java.util.Collection;
  
  import org.altbeacon.beacon.Beacon;
  import org.altbeacon.beacon.BeaconConsumer;
  import org.altbeacon.beacon.BeaconManager;
  import org.altbeacon.beacon.BeaconParser;
  import org.altbeacon.beacon.Identifier;
  import org.altbeacon.beacon.RangeNotifier;
  import org.altbeacon.beacon.Region;
  
  import android.app.Service;
  import android.content.Intent;
  import android.os.IBinder;
  import android.os.RemoteException;
  import android.util.Log;
  
  
  public class TestBestzBeaconService extends Service implements BeaconConsumer
  {
  
      private BeaconManager beaconManager;
      private final String BEACON_UUID = "11687109-915f-4136-a1f8-e60ff514f96d";
      private final int BEACON_MAJOR = 3;
  
      @Override
      public void onCreate() {
          super.onCreate();
          L.p("In TestBestzBeaconService onCreate()");
      }
  
      @Override
      public IBinder onBind(Intent intent) {
          return null;
      }
  
      @Override
      public int onStartCommand (Intent intent, int flags, int startId) {
          L.p("in TestBestzBeaconService onStartCommand()");
  
          beaconManager = BeaconManager.getInstanceForApplication(this);
          beaconManager.bind(this);
  
          //iBeacons ?
          BeaconParser bp0 = new BeaconParser();
          bp0.setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24");
          beaconManager.getBeaconParsers().add(bp0);
  
          //Bluecats?
          BeaconParser bp1 = new BeaconParser();
          bp1.setBeaconLayout("m:2-3=0201,i:28-29,p:24-24");
          beaconManager.getBeaconParsers().add(bp1);
  
          return super.onStartCommand(intent, flags, startId);    
      }
  
      @Override
      public void onDestroy() {
          L.p("In TestBestzBeaconService onDestroy()");
          beaconManager.unbind(this);
      }
  
  
      @Override
      public void onBeaconServiceConnect() {
  
          L.p("In TestBestzBeaconService onBeaconServiceConnect()");
  
          beaconManager.setRangeNotifier(new RangeNotifier() {
              @Override
              public void didRangeBeaconsInRegion(Collection&lt;Beacon&gt; arg0, Region arg1) {
                  L.p("In TestBestzBeaconService - anonymous didRangeBeaconsInRegion()");
              }
          });
  
          Region region = new Region("myregion", Identifier.parse(BEACON_UUID), Identifier.fromInt(BEACON_MAJOR), null); //
  
          try {
              beaconManager.startRangingBeaconsInRegion(region);
          } catch (RemoteException e) {
              L.p("In TestBestzBeaconService onBeaconServiceConnect(), REMOTEEXCEPTION!");
          }
  
      }
  
      private static class L
      {
          public static void p(String s) {
              Log.i("beacon", s);
          }
      }
  
  }
  </code></pre>
  
  <p>I'm calling this from an Activity as so:</p>
  
  <pre><code>public class MainActivity extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          startService(new Intent(this, TestBestzBeaconService.class));
      }
  
  }
  </code></pre>
  
  <p>The log output I'm getting is:</p>
  
  <pre><code>03-19 09:56:40.233: I/beacon(25210): In TestBestzBeaconService onCreate()
  03-19 09:56:40.233: I/beacon(25210): in TestBestzBeaconService onStartCommand()
  03-19 09:56:40.566: I/beacon(25210): In TestBestzBeaconService onBeaconServiceConnect()
  </code></pre>
  
  <p>Parts added to the <code>AndroidManifest</code>:</p>
  
  <pre><code>&lt;!-- Needed for AltBeacon SDK --&gt;
  &lt;uses-permission android:name="android.permission.BLUETOOTH"/&gt;
  &lt;uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/&gt;
  </code></pre>
  
  <p>and inside the <code>Application</code> tag:</p>
  
  <pre><code>&lt;!-- Needed for AltBeacon SDK --&gt;
  &lt;service android:name="org.altbeacon.beacon.service.BeaconService"/&gt;
  &lt;service android:name="com.ibeacontest.android.TestBestzBeaconService" /&gt;
  </code></pre>
  
  <p>...but no signs of beacons or the <code>didRangeBeaconsInRegion</code> log output. Any pointers?</p>