Estimote iBeacon: Monitoring in background (Android)

后端 未结 2 1532
误落风尘
误落风尘 2020-12-30 16:32

I would like to have push notifications when my app is open but is in background. For now I have changed the Estimote Demo, and my app gives me a notification when my app is

2条回答
  •  情书的邮戳
    2020-12-30 17:12

    You should create service.

    In your code you should do some changes.

    After

    beaconManager = new BeaconManager(this);

    you should start "beacon service"

          if (!beaconManager.isBluetoothEnabled()) {
              stopSelf();
          }
    
              beaconManager.connect(new BeaconManager.ServiceReadyCallback() {
                  @Override
                  public void onServiceReady() {
                    try {
                      beaconManager.startRanging(ALL_ESTIMOTE_BEACONS_REGION);
                    } catch (RemoteException e) {
                      Log.e("error", "Cannot start ranging", e);
                    }
                  }
              });
    

    Also check if Bluetooth is active on you device.

    In procedure beaconManager.setMonitoringListener(new MonitoringListener() add commands to create Notifications.

提交回复
热议问题