You can set a predicate on the Urban Airship action that launches the URL or you can replace it with your own custom action and route the handling to your own activity. This is done through Urban Airship's Actions Framework.
Using a Predicate
Setting a predicate allows filtering on when an action can run and can be used to specify alternative actions for different situations. The open external URL action allows launching any URL and is registered with the name open_external_url_action
. To set a predicate, first lookup the entry in the ActionRegistry
using the action name.
ActionRegistry.Entry entry = UAirship.shared()
.getActionRegistry()
.getEntry("open_external_url_action");
You can then set a predicate on the action that will be called before the Urban Airship SDK opens the URL.
// Predicate that will prevent the action from running if launched from a push notification. Return false to stop the action from running.
Predicate<ActionArguments> openExternalURLPredicate = new Predicate<ActionArguments>() {
@Override
public boolean apply(ActionArguments arguments) {
return !(Situation.PUSH_OPENED.equals(arguments.getSituation()));
}
};
entry.setPredicate(openExternalURLPredicate);
The URL is included in the ActionArguments
:
arguments.getValue().getString()
Using a Custom Action
To completely replace the Urban Airship action, define your action and set it after takeOff.
public class CustomAction extends Action {
@Override
public boolean acceptsArguments(ActionArguments arguments) {
if (!super.acceptsArguments(arguments)) {
return false;
}
// Do any argument inspections. The action will stop
// execution if this method returns false.
return true;
}
@Override
public ActionResult perform(ActionArguments arguments) {
Logger.info("Action is performing!");
return ActionResult.newEmptyResult();
}
}
Register the action after takeOff with the name open_external_url_action
:
@Override
public void onAirshipReady(UAirship airship) {
airship.getActionRegistry()
.registerAction(new CustomAction(), "open_external_url_action");
}
You can also take a look at what the OpenExternalUrlAction
is doing here and review Urban Airship's documentation.