public void startBeaconMonitoring() {
    verifyBluetooth();

    for (String type : beaconTypes) {
      beaconManager.getBeaconParsers().add(getParser(type));
    }

    Log.d(TAG, "Starting Beacon monitoring...");

    Region region = new Region("backgroundRegion", null, null, null);
    regionBootstrap = new RegionBootstrap(this, region);

    backgroundPowerSaver = new BackgroundPowerSaver(context);
    beaconManager.bind(this);
  }
Esempio n. 2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.user);
    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,d:25-25"));
    beaconManager.bind(this);

    logToDisplay(userTypeActivity.userTypeDef);

    sendRequest = (Button) findViewById(R.id.sendRequest);
    sendRequest.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            onBeaconServiceConnect();
          }
        });
  }
  public void onCreate() {
    super.onCreate();
    mBeaconManager = org.altbeacon.beacon.BeaconManager.getInstanceForApplication(this);

    // By default the AndroidBeaconLibrary will only find AltBeacons.  If you wish to make it
    // find a different type of beacon, you must specify the byte layout for that beacon's
    // advertisement with a line like below.  The example shows how to find a beacon with the
    // same byte layout as AltBeacon but with a beaconTypeCode of 0xaabb.  To find the proper
    // layout expression for other beacon types, do a web search for "setBeaconLayout"
    // including the quotes.
    //
    mBeaconManager.getBeaconParsers().clear();
    mBeaconManager
        .getBeaconParsers()
        .add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));

    Log.d(TAG, "setting up background monitoring for beacons and power saving");
    // wake up the app when a beacon is seen
    Region region = new Region("backgroundRegion", null, null, null);
    regionBootstrap = new RegionBootstrap(this, region);

    // simply constructing this class and holding a reference to it in your custom Application
    // class will automatically cause the BeaconLibrary to save battery whenever the application
    // is not visible.  This reduces bluetooth power usage by about 60%
    backgroundPowerSaver = new BackgroundPowerSaver(this);

    // If you wish to test beacon detection in the Android Emulator, you can use code like this:

    //        BeaconManager.setBeaconSimulator(new TimedBeaconSimulator() );
    //        ((TimedBeaconSimulator)
    // BeaconManager.getBeaconSimulator()).createTimedSimulatedBeacons();

    mBeaconManager.bind(this);

    SugarContext.init(getApplicationContext());
  }
 public void startScan() {
   mBeaconManager.bind(this);
 }
Esempio n. 5
0
 /** 开始监控beacons,绑定BeaconService,如果已经绑定,在BeaconManger的bind()中忽略之。 建议在应用程序中执行一次该函数即可。 */
 public void openSearcher() {
   // 设置beacon消费者,绑定BeaconService,BeaconSearcher的实例以产生,即绑定BeaconService
   // 进而触发mBeaconConsumer的onBeaconServiceConnect(),开始监控特定区域的Beacons。
   mBeaconManager.bind(mBeaconConsumer);
 }