2014-11-21 42 views
2

我正在使用Altbeacon庫來掃描信標。有廣告時,我已成功掃描並推送通知。我的要求是我需要掃描UUID列表,但文檔中給出的示例僅使用一個UUID進行掃描。Altbeacon - 掃描陣列中的多個UUID

這裏是我做的,到目前爲止,我把BeaconConsumer我BaseActivity,使其發射(無後臺掃描)後立即啓動掃描:

public class BaseActivity extends SlidingFragmentActivity implements BeaconConsumer { 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     ... 

     beaconManager = BeaconManager.getInstanceForApplication(this); 
     beaconManager.getBeaconParsers().add(new BeaconParser(). 
       setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24")); 
     beaconManager.bind(this); 
    } 

    @Override 
    public void onBeaconServiceConnect() { 
     beaconManager.setMonitorNotifier(new MonitorNotifier() { 
      @Override 
      public void didEnterRegion(Region region) { 
       Intent intent = new Intent(getApplicationContext(), BeaconNotificationService.class); 
       intent.putExtra("uuid", region.getId1().toString()); 
       intent.putExtra("major", region.getId2().toString()); 
       intent.putExtra("minor", region.getId3().toString()); 
       intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
       startService(intent); 
      } 

      @Override 
      public void didExitRegion(Region region) { 
       Log.i(TAG, "I no longer see any beacon"); 
      } 

      @Override 
      public void didDetermineStateForRegion(int state, Region region) { 
       Log.i(TAG, "I have just switched from seeing/not seeing beacons: "+state); 
      } 
     }); 

     try { 
      beaconManager.startMonitoringBeaconsInRegion(new Region("com.my.app.boostrapRegion", 
        Identifier.parse(Constants.BT_UUID), 
        Identifier.fromInt(Constants.BT_MAJOR), 
        Identifier.fromInt(Constants.BT_MINOR))); 
     } catch (RemoteException e) { e.printStackTrace(); } 
    } 

} 

常量類中,我定義我的UUID測試目的:

public class Constants { 

    public static final String BT_UUID = "bbbbbbbb-3443-8888-3443-bb323bbb0005"; 
    public static final int BT_MAJOR = 0; 
    public static final int BT_MINOR = 0; 

} 

我該如何放置一個由BeaconConsumer掃描的UUID數組?

感謝

回答

1

而不是定義在該地區UUID的,你可以添加null,找到範圍內的所有的信標。之後您可以過濾掉您正在尋找的信標。 在這個例子中,爲了清晰起見,我保留了主要和次要ID。

try { 
    beaconManager.startMonitoringBeaconsInRegion(new Region("com.kedai.baucar.boostrapRegion", 
    null, 
    Identifier.fromInt(Constants.BT_MAJOR), 
    Identifier.fromInt(Constants.BT_MINOR))); 
} catch (RemoteException e) { e.printStackTrace(); }