问题
Actually I want to override the behaviour of external web page action and modify the app flow . But It is not suppprted or I didn't able to do that. Please help me get the action in our app and redirect as per my requirment.
More detail : I sent a web page notification from UA and my application just launch and open the external web page (It all handles by UA SDk) but due to some internal task Home activity takes time to launch and when It launched It put the web page in background , I want to show web page on top.
回答1:
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.
来源:https://stackoverflow.com/questions/49530003/urban-airship-override-the-behavour-of-openexternalurlaction-action