コード例 #1
0
 public WMBeaconManager(
     MonitorNotifier monitorNotifier, RangeNotifier rangeNotifier, Context context) {
   this.context = context;
   mBeaconManager = BeaconManager.getInstanceForApplication(this.context);
   // Detect the main Eddystone-UID frame:
   mBeaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout(EDDYSTONE_LAYOUT));
   mBeaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout(IBEACON_LAYOUT));
   mBeaconManager.setRangeNotifier(rangeNotifier);
   mBeaconManager.setMonitorNotifier(monitorNotifier);
 }
コード例 #2
0
 @Override
 public void onCreate() {
   mAllBeaconsRegion = new Region("all beacons", null, null, null);
   mBeaconManager = BeaconManager.getInstanceForApplication(this);
   mBackgroundPowerSaver = new BackgroundPowerSaver(this);
   mRegionBootstrap = new RegionBootstrap(this, mAllBeaconsRegion);
   /* ibeacon layout */
   mBeaconManager.setForegroundScanPeriod(500);
   mBeaconManager
       .getBeaconParsers()
       .add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
 }
コード例 #3
0
  public BeaconSearcher(Context context) {

    this.mContext = context.getApplicationContext();

    this.mBeaconManager = BeaconManager.getInstanceForApplication(mContext);

    // 经过测试,天津的Beacon应该是Apple的Beacon,beaconTypeCode=0215
    // 其传输帧的字节序列按照以下顺序传输,但是网络上查到2013年后的Estimote beacons也是下列的字节顺序,ok
    // mBeaconManager.getBeaconParsers().add(new
    // BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));

    // 也可能是AltBeacon(即Radius)的Beacon,ok
    mBeaconManager
        .getBeaconParsers()
        .add(new AltBeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));

    // 设置距离计算模型
    DefaultDistanceCalcuator defaultDistanceCalcuator = new DefaultDistanceCalcuator(mContext);
    // 使用asserts/model-distance-calculations.json
    defaultDistanceCalcuator.setDefaultDistanceCalcuator(null);
    // 使用url
    // defaultDistanceCalcuator.setDefaultDistanceCalcuator("http://data.altbeacon.org/android-distance.json");

    // 设置发现beacon监听回调,看到beacon,看不到beacon; 进入,离开,临界状态
    // Specifies a class that should be called each time the BeaconService
    // sees or stops seeing a Region of beacons.
    // IMPORTANT: Only one MonitorNotifier may be active for a given
    // application. If two different activities or services set different
    // MonitorNotifier instances, the last one set will receive all the
    // notifications.
    mBeaconManager.setMonitorNotifier(mMonitorNotifier);

    // 设置测距修正回调,每个扫描周期结束,根据20秒内各beacon的RSSI平均值计算它的距离,该回调获取这些beacon的距离值
    // Specifies a class that should be called each time the BeaconService
    // gets ranging data, which is nominally once per
    // second(实际上每个扫描周期,计算一次距离) when beacons are detected.
    // IMPORTANT: Only one RangeNotifier may be active for a given
    // application. If two different activities or services set different
    // RangeNotifier instances,
    // the last one set will receive all the notifications.
    mBeaconManager.setRangeNotifier(mRangeNotifier);

    // 当程序切换到后台,BeaconService自动切换到后台模式,为了省电,蓝牙扫描频率降低;程序恢复到前台,BeaconService也跟随恢复至前台
    // 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%
    Context appContext = this.mContext.getApplicationContext();
    mBackgroundPowerSaver = new BackgroundPowerSaver(appContext);
  }
コード例 #4
0
  public void onCreate() {
    super.onCreate();
    BeaconManager beaconManager =
        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.
    //
    // beaconManager.getBeaconParsers().add(new BeaconParser().
    //        setBeaconLayout("m:2-3=aabb,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"));
    //
    beaconManager
        .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);
    ArrayList<Region> regionList = new ArrayList<Region>();
    regionList.add(
        new Region(
            "1",
            Identifier.parse(getString(R.string.uuid)),
            Identifier.parse(getString(R.string.major)),
            Identifier.parse("1")));
    regionList.add(
        new Region(
            "2",
            Identifier.parse(getString(R.string.uuid)),
            Identifier.parse(getString(R.string.major)),
            Identifier.parse("2")));
    regionList.add(
        new Region(
            "3",
            Identifier.parse(getString(R.string.uuid)),
            Identifier.parse(getString(R.string.major)),
            Identifier.parse("3")));
    regionBootstrap = new RegionBootstrap(this, regionList);

    // 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();
  }
コード例 #5
0
  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);
  }
コード例 #6
0
ファイル: UserActivity.java プロジェクト: angelo5014/Apollo
  @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();
          }
        });
  }
コード例 #7
0
  @Override
  public void onCreate() {
    super.onCreate();

    Parse.enableLocalDatastore(getApplicationContext());

    // Add your initialization code here
    Parse.initialize(
        this,
        "3auP8OKsyBVdwDFFhQ7bAINSFldjA0zYrrSiKjIx",
        "FE0F9uUocCMzPiSyMl0UoEWDT1tdzYs3MOcQwp3O");

    ParseUser.enableAutomaticUser();
    ParseACL defaultACL = new ParseACL();

    // If you would like all objects to be private by default, remove this line.
    defaultACL.setPublicReadAccess(true);

    ParseACL.setDefaultACL(defaultACL, true);

    //   PushService.setDefaultPushCallback(this, MainActivity.class);

    ParseInstallation.getCurrentInstallation().saveInBackground();

    ParseQuery<ParseObject> queryDrinks = new ParseQuery<>("ls_drinks");
    queryDrinks.setLimit(200);

    queryDrinks.findInBackground(
        new FindCallback<ParseObject>() {
          public void done(final List<ParseObject> object, ParseException e) {
            // Remove the previously cached results.
            ParseObject.unpinAllInBackground(
                "ls_drinks",
                new DeleteCallback() {
                  public void done(ParseException e) {
                    // Cache the new results.
                    ParseObject.pinAllInBackground("ls_drinks", object);
                  }
                });
          }
        });

    ParseQuery<ParseObject> queryMenu = new ParseQuery<>("ls_menu");
    // Locate the column named "day" in Parse.com and order list
    // by ascending

    queryMenu.findInBackground(
        new FindCallback<ParseObject>() {
          public void done(final List<ParseObject> object, ParseException e) {
            // Remove the previously cached results.
            ParseObject.unpinAllInBackground(
                "ls_menu",
                new DeleteCallback() {
                  public void done(ParseException e) {
                    // Cache the new results.
                    ParseObject.pinAllInBackground("ls_menu", object);
                  }
                });
          }
        });

    ParseQuery<ParseObject> queryReviews = new ParseQuery<>("ls_reviews");
    // Locate the column named "day" in Parse.com and order list
    // by ascending

    queryReviews.findInBackground(
        new FindCallback<ParseObject>() {
          public void done(final List<ParseObject> object, ParseException e) {
            // Remove the previously cached results.
            ParseObject.unpinAllInBackground(
                "ls_reviews",
                new DeleteCallback() {
                  public void done(ParseException e) {
                    // Cache the new results.
                    ParseObject.pinAllInBackground("ls_reviews", object);
                  }
                });
          }
        });

    ParseQuery<ParseObject> queryGroups = new ParseQuery<>("ls_groups");
    // Locate the column named "day" in Parse.com and order list
    // by ascending

    queryGroups.findInBackground(
        new FindCallback<ParseObject>() {
          public void done(final List<ParseObject> object, ParseException e) {
            // Remove the previously cached results.
            ParseObject.unpinAllInBackground(
                "ls_groups",
                new DeleteCallback() {
                  public void done(ParseException e) {
                    // Cache the new results.
                    ParseObject.pinAllInBackground("ls_groups", object);
                  }
                });
          }
        });

    Log.d(TAG, "App started up");

    BeaconManager 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"));

    String blueUUID = "b7d1027d-6788-416e-994f-ea11075f1765";

    Region region =
        new Region("comapps.com.lakewoodsmokehouse", Identifier.parse(blueUUID), null, null);

    regionBootstrap = new RegionBootstrap(this, region);

    BeaconManager.setDebug(true);
  }