Estimote iBeacon: Monitoring in background (Android)

后端 未结 2 1519
误落风尘
误落风尘 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 16:53

    You should hold BeaconManager in your application class not in the activity.

    Activity will be stopped, destroyed and BeaconManager will stop monitoring. Application on the other hand will still hold reference and will continue to monitor.

    When a beacon is being found while monitoring your application class can post a notification. It trigger some activity when user decides to tap on it.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题