Search code examples
javaandroidandroid-studiopush-notificationandroid-broadcastreceiver

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


I see in the documentation of Plot Project that GeotriggerHandlerReceiver should be used, but according to Android Studio for the version com.plotprojects:plot-android:2.4.0-beta this Receiver is already deprecated.

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;
    }
}

Solution

  • Indeed we're deprecating the GeotriggerHandlerReceiver and will remove it in the next version. In order to maintain your code up to date follow this guide. The guide explains why and how to do this.

    We're in the process of updating our documentation to make it more organised and complete.

    Cheers!