In the Plot Projects plugin version 2.4, we introduce a breaking change in order to support the new Android OS version, Oreo (8.0). This adjustment is justified by a new restriction imposed by the OS, which blocks apps from starting service intents (IntentService) in the background. Considering that both the Notification Filter and the Geotrigger Handler relied on service intents, we had to adapt to the new regulation, so our solution moved to Broadcasts. Consequently, the implementation of custom filters and handlers on the client side also changed slightly. However, the old classes NotificationFilterReceiver and GeotriggerHandlerReceiver are still available but have been deprecated.

This guide shows what is needed to get custom filters and handlers up and running with the plugin version 2.4, in comparison with the old versions.

Notification Filter

On the previous versions, in order to implement a custom notification filter you had to extend the class NotificationFilterReceiver, however this class has been deprecated and the replaced by a new class called NotificationFilterBroadcastReceiver. The only impact of this change is that the application context (Context) is no longer directly accessible but rather through a method named getContext(). The code below represents an example implementation of a custom Notification Filter:

//Example implementation for filterNotifications:
public class MyNotificationFilterReceiver extends NotificationFilterBroadcastReceiver {
    @Override
    public List filterNotifications(List notifications) {
        Context context = getContext();
        String appName = context.getString(R.string.app_name);
        String format = "Hello from %s: %s";
 
        for (FilterableNotification notification : notifications) {
            String newMessage = String.format(format, appName, notification.getMessage());
            notification.setMessage(newMessage);
        }
        return notifications;
    }
}
Geotrigger Handler

Similar to the notification filter, in the new version of the plugin the class GeotriggerHandlerReceiver has been deprecated and the class GeotriggerHandlerBroadcastReceiver has taken over.

The application context can be accessed the same way as in the notification filter, through the method getContext(). The code below represents an example implementation of a custom Geotrigger Handler:

//Example implementation for handleGeotriggers:
public class MyGeotriggerHandlerReceiver extends GeotriggerHandlerBroadcastReceiver {
    @Override
    public List handleGeotriggers(List geotriggers) {
        List passedGeotriggers = new ArrayList();
        for (Geotrigger geotrigger : geotriggers) {
            String data = geotrigger.getData();
            if (data.equals("pass")) {
                passedGeotriggers.add(geotrigger);
            }
        }
        return passedGeotriggers;
    }
}
Declaring the classes in the Manifest

After creating the custom classes representing the filter and/or the handler, you need to declare them as receivers (instead of services) in the AndroidManifest.xml file which can be done as follows:

<receiver
android:name=".MyNotificationFilterReceiver"
android:exported="false">
<intent-filter>
<action android:name="${applicationId}.plot.FilterNotifications" />
</intent-filter>
</receiver>

<receiver
android:name=".MyGeotriggerHandlerReceiver"
android:exported="false">
<intent-filter>
<action android:name="${applicationId}.plot.HandleGeotriggers">
<intent-filter>
<receiver>