GeotriggerHandlerReceiver 在 PlotProjects 中被弃用。什么是替代使用?

GeotriggerHandlerReceiver is deprecated in PlotProjects. What is the alternative to use?

我在 Plot Project 的文档中看到应该使用 GeotriggerHandlerReceiver,但是根据 Android Studio 的版本 com.plotprojects:plot-android:2.4.0-beta此接收器已被弃用。

Image from Android Studio

3.5 Geotrigger handler When you want to handle your geotriggers, or use them as trigger events for your own code, you can use the geotrigger handler. Plot automatically detects whether a service is registered in AndroidManifest.xml that extends from the class GeotriggerHandlerReceiver. Implementations of GeotriggerHandlerReceiver must implement the method public List handleGeotriggers(List geotriggers). When the service is defined, Plot will send the geotriggers to this method before considering them as handled. This allows you to add custom code that is triggered by entering (or exiting) a geofence or beacon region.

//Example implementation for handleGeotriggers:
public class MyGeotriggerHandlerReceiver extends GeotriggerHandlerReceiver {
    @Override
    public List<Geotrigger> handleGeotriggers(List<Geotrigger> geotriggers) {
        List<Geotrigger> passedGeotriggers = new ArrayList<Geotrigger>();
            for (Geotrigger geotrigger : geotriggers) {
                String data = geotrigger.getData();
                if (data.equals("pass")) {
                    passedGeotriggers.add(geotrigger);
            }
        }
        return passedGeotriggers;
    }
}

事实上,我们正在弃用 GeotriggerHandlerReceiver 并将在下一个版本中将其删除。为了使您的代码保持最新,请遵循此 guide。该指南解释了为什么以及如何执行此操作。

我们正在更新我们的文档以使其更有条理和完整。

干杯!