What is the correct procedure to set up and register custom events for the Android platform.
I have been through the documentation repeatedly - however cannot see a simple straightforward example of how to do this.
What I need:
From clicking a notification, i need to be able to distinguish between 3 scenarios - that need to perform different actions
- The 3 scenarios are:
1. Simple deep link message sent that contains a URI - based on the URI - the user will be taken to either of two different Activities (screens)
2. An inbox message sent ,that when the notification is received - the user clicks on it - and the Inbox message opens directly into a default browser, displaying the html/css
3. A push message that contains some data - that when the user clicks on the notification - the user will be taken to different Activities (screens), based on that data
What I have:
In trying to follow the documentation, and sample app, I have created 3 classes that subclass the Action class
One example
public class InboxMessageCustomAction extends Action {
public static final String DEFAULT_REGISTRY_NAME = "open_mc_action";
/**
* Default registry short name
*/
public static final String DEFAULT_REGISTRY_SHORT_NAME = "^mc";
public static final String MESSAGE_ID_PLACEHOLDER = "auto";
@Override
public boolean acceptsArguments(@NonNull ActionArguments arguments) {
switch (arguments.getSituation()) {
case SITUATION_PUSH_OPENED:
case SITUATION_WEB_VIEW_INVOCATION:
case SITUATION_MANUAL_INVOCATION:
case SITUATION_FOREGROUND_NOTIFICATION_ACTION_BUTTON:
case SITUATION_AUTOMATION:
return true;
case SITUATION_BACKGROUND_NOTIFICATION_ACTION_BUTTON:
case SITUATION_PUSH_RECEIVED:
default:
return false;
}
}
@NonNull
@Override
public ActionResult perform(@NonNull ActionArguments arguments) {
String messageId = arguments.getValue().getString();
if (MESSAGE_ID_PLACEHOLDER.equalsIgnoreCase(messageId)) {
PushMessage pushMessage = arguments.getMetadata().getParcelable(ActionArguments.PUSH_MESSAGE_METADATA);
if (pushMessage != null && pushMessage.getRichPushMessageId() != null) {
messageId = pushMessage.getRichPushMessageId();
} else if (arguments.getMetadata().containsKey(ActionArguments.RICH_PUSH_ID_METADATA)) {
messageId = arguments.getMetadata().getString(ActionArguments.RICH_PUSH_ID_METADATA);
} else {
messageId = null;
}
}
if (UAStringUtil.isEmpty(messageId)) {
UAirship.shared().getInbox().startInboxActivity();
} else {
UAirship.shared().getInbox().startMessageActivity(messageId);
}
return ActionResult.newEmptyResult();
}
@Override
public boolean shouldRunOnMainThread() {
return true;
}
}
In my launch Activity I have a method that monitors the registration of these Actions
public class ActionMonitor {
public ActionMonitor() { }
public void start() {
InboxMessageCustomAction inboxMessageCustomAction = new InboxMessageCustomAction();
CustomSpecialMessageAction specialMessageAction = new CustomSpecialMessageAction();
DeepLinkCustomAction deepLinkCustomAction = new DeepLinkCustomAction();
ActionRegistry registry = UAirship.shared().getActionRegistry();
registry.getEntry(DeepLinkAction.DEFAULT_REGISTRY_NAME).setDefaultAction(inboxMessageCustomAction);
registry.getEntry(DeepLinkAction.DEFAULT_REGISTRY_NAME).setDefaultAction(specialMessageAction);
registry.getEntry(DeepLinkAction.DEFAULT_REGISTRY_NAME).setDefaultAction(deepLinkCustomAction);
ActionRunRequest.createRequest("deep_link_action")
.setValue("actionValue")
.setSituation(SITUATION_PUSH_OPENED)
.run();
ActionRunRequest.createRequest("my_custom_special_message_action")
.setValue("actionValue")
.setSituation(SITUATION_PUSH_OPENED)
.run();
ActionRunRequest.createRequest("inbox_message_custom_action")
.setValue("actionValue")
.setSituation(SITUATION_PUSH_OPENED)
.run();
}
And have set up the auto takeoff by registering in the AndroidManifest that references this class:
public class UASetup extends Autopilot {
@Override
public void onAirshipReady(@NonNull UAirship airship) {
PushManager pushManager = UA.getPushManager();
String channelId = pushManager.getChannelId();
airship.getActionRegistry()
.registerAction(new CustomSpecialMessageAction(), "special_message_action");
airship.getActionRegistry()
.registerAction(new DeepLinkCustomAction(), "deep_link_action");
airship.getActionRegistry()
.registerAction(new InboxMessageCustomAction(), "inbox_message_custom_action");
Timber.d("Urban airship channel id %s",channelId);
}
@Override
public AirshipConfigOptions createAirshipConfigOptions(@NonNull Context context) {
AirshipConfigOptions options = new AirshipConfigOptions.Builder()
.setProductionAppKey("xxxxxxxxxxxxxxxxxxxx")
.setProductionAppSecret("xxxxxxxxxxxxxxxxx")
.setDevelopmentAppKey("xxxxxxxxxxxxxxxxxxx")
.setDevelopmentAppSecret("xxxxxxxxxxxxxxxx")
.setInProduction(!BuildConfig.DEBUG)
.setFcmSenderId("000000000000") // FCM/GCM sender ID
.setNotificationIcon(R.drawable.tickets)
.setNotificationAccentColor(Color.BLUE)
.build();
return options;
}
}
What I want
What i want to know is, am i missing any steps. Also - how do I distinguish between these 3 notifications. For instance if users click on a notification - it could be any of the three - but they all have different actions to perform.
I hope I am explaining myself correctly. Any help would be appreciated
Many thanks
Paul
Comments
1 comment