Dealing with user tapping on notification
Android¶
The default behavior when tapping a notification is opening a URI. If you want a different action, then you have to write your own BroadcastReceiver.
An example of a custom receiver which starts the NotificationOpenActivity (see our example project):
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import com.plotprojects.retail.android.FilterableNotification;
public class MyNotificationOpenReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
FilterableNotification notification = intent.getParcelableExtra("notification");
if (notification.getData() == null)
return;
Intent openIntent = new Intent(context, NotificationOpenActivity.class);
openIntent.setAction(NotificationOpenActivity.ACTION);
openIntent.putExtras(intent.getExtras());
openIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
context.startActivity(openIntent);
}
}
And to add this receiver to the manifest instead of the default one:
<receiver android:exported="false" android:name="com.example.MyNotificationOpenReceiver">
<intent-filter>
<action android:name="${applicationId}.plot.OpenNotification" />
</intent-filter>
</receiver>
Appcelerator¶
When you don't specify a callback for handling notifications, Plot will handle the notifications depending on the action setting in the dashboard. You can for instance set the field to a URI and whenver the notification is opened the URI will be loaded with the phone's browser.
If you don’t want Plot to handle the notifications, you can handle the notifications yourself. To change the action when a notification has been received you can add a listener as shown in the snippet below. The function is passed a notification object, which has the fields "message", "data" and "identifier". When no listener is added, then the "data" field will be treated as set in the dashboard.
plot.addEventListener("plotNotificationReceived", func)
Phonegap¶
When you don't specify a callback for handling notifications, Plot will handle the notifications depending on the action setting in the dashboard. You can for instance set the field to a URI and whenever the notification is opened the URI will be loaded with the phone's browser.
If you don’t want Plot to handle the notifications, you can handle the notifications yourself. To change the action when a notification has been received you can use the notificationHandler
. This feature is available both on IOS and Android.
An example of such an implementation:
//Optional, by default the data is treated as set in the dashboard.
plot.notificationHandler = function(notification, data) {
alert(data);
}