Пример #1
0
  private void verifyBluetooth() {

    try {
      if (!BeaconManager.getInstanceForApplication(getApplicationContext()).checkAvailability()) {
        final AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
        builder.setTitle("Bluetooth not enabled");
        builder.setMessage("Please enable bluetooth in settings and restart this application.");
        builder.setPositiveButton(android.R.string.ok, null);
        builder.setOnDismissListener(
            new DialogInterface.OnDismissListener() {
              @Override
              public void onDismiss(DialogInterface dialog) {
                System.exit(0);
              }
            });
        builder.show();
      }
    } catch (RuntimeException e) {
      final AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
      builder.setTitle("Bluetooth LE not available");
      builder.setMessage("Sorry, this device does not support Bluetooth LE.");
      builder.setPositiveButton(android.R.string.ok, null);
      builder.setOnDismissListener(
          new DialogInterface.OnDismissListener() {

            @Override
            public void onDismiss(DialogInterface dialog) {
              System.exit(0);
            }
          });
      builder.show();
    }
  }
Пример #2
0
 @Override
 public void onCreate() {
   super.onCreate();
   // Allow scanning to continue in the background.
   backgroundPowerSaver = new BackgroundPowerSaver(this);
   beaconManager = BeaconManager.getInstanceForApplication(this);
 }
 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);
 }
public class RangingActivity extends Activity {
  protected static final String TAG = "RangingActivity";
  private BeaconManager beaconManager = BeaconManager.getInstanceForApplication(this);

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_ranging);
  }

  @Override
  protected void onDestroy() {
    super.onDestroy();
  }

  @Override
  protected void onPause() {
    super.onPause();
    // Tell the Application not to pass off ranging updates to this activity
    ((BeaconReferenceApplication) this.getApplication()).setRangingActivity(null);
  }

  @Override
  protected void onResume() {
    super.onResume();
    // Tell the Application to pass off ranging updates to this activity
    ((BeaconReferenceApplication) this.getApplication()).setRangingActivity(this);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
  }

  public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
    if (beacons.size() > 0) {
      EditText editText = (EditText) RangingActivity.this.findViewById(R.id.rangingText);
      for (Beacon beacon : beacons) {
        logToDisplay(
            "Beacon "
                + beacon.toString()
                + " is about "
                + beacon.getDistance()
                + " meters away, with Rssi: "
                + beacon.getRssi());
      }
    }
  }

  private void logToDisplay(final String line) {
    runOnUiThread(
        new Runnable() {
          public void run() {
            EditText editText = (EditText) RangingActivity.this.findViewById(R.id.rangingText);
            editText.append(line + "\n");
          }
        });
  }
}
Пример #5
0
  @Override
  public void onReceive(Context context, Intent intent) {
    if (!Adbeacon.isAllowService(context)) return;

    try {
      if (Adbeacon.isOnline(context)
          && BeaconManager.getInstanceForApplication(context).checkAvailability())
        context.startService(new Intent(context, AdbeaconService.class));
    } catch (RuntimeException e) {
    }
  }
Пример #6
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"));
 }
Пример #7
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);
  }
  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();
  }
  public ThunderBoardPowerSaver(Context context, PreferenceManager preferenceManager) {

    if (android.os.Build.VERSION.SDK_INT < 18) {
      Timber.d("BackgroundPowerSaver requires API 18 or higher.");
      return;
    }

    if (context instanceof Application) {
      ((Application) context).registerActivityLifecycleCallbacks(this);
    } else {
      Timber.e("Context is not an application instance, so we cannot use the BackgroundPowerSaver");
    }

    this.preferenceManager = preferenceManager;
    this.beaconManager = BeaconManager.getInstanceForApplication(context);
  }
  @Override
  public void onReceive(Context context, Intent intent) {
    BeaconManager.logDebug(TAG, "onReceive called in startup broadcast receiver");
    if (android.os.Build.VERSION.SDK_INT < 18) {
      Log.w(
          TAG,
          "Not starting up beacon service because we do not have SDK version 18 (Android 4.3).  We have: "
              + android.os.Build.VERSION.SDK_INT);
      return;
    }
    BeaconManager beaconManager =
        BeaconManager.getInstanceForApplication(context.getApplicationContext());

    Intent startServiceIntent = new Intent(context, BeaconService.class);
    context.startService(startServiceIntent);
    startServiceIntent = new Intent(context, BeaconIntentProcessor.class);
    context.startService(startServiceIntent);
  }
Пример #11
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();
          }
        });
  }
Пример #12
0
 public MeshbluBeacon(Meshblu meshblu, Context context) {
   this.meshblu = meshblu;
   this.context = context;
   beaconManager = BeaconManager.getInstanceForApplication(context);
 }
Пример #13
0
 public MeshbluBeacon(SaneJSONObject meshbluConfig, Context context) {
   this.meshblu = new Meshblu(meshbluConfig, context);
   this.context = context;
   beaconManager = BeaconManager.getInstanceForApplication(context);
 }
  @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);
  }