deleteIntent.putExtra(NOTIFICATION_EXTRA_INTERACTION_TYPE, interaction.getType().name()); deleteIntent.putExtra(NOTIFICATION_EXTRA_INTERACTION_DEFINITION, interaction.toString()); deleteIntent.setAction(NOTIFICATION_ACTION_DELETE); PendingIntent deletePendingIntent = PendingIntent.getBroadcast(context, new Random().nextInt(), deleteIntent, PendingIntent.FLAG_ONE_SHOT); if (!StringUtils.isNullOrEmpty(interaction.getTitle())) { builder.setContentTitle(interaction.getTitle()); bigTextStyle.setBigContentTitle(interaction.getTitle()); if (!StringUtils.isNullOrEmpty(interaction.getBody())) { builder.setContentText(interaction.getBody()); bigTextStyle.bigText(interaction.getBody()); Actions actions = interaction.getActions(); if (actions != null) { List<Action> actionsList = actions.getAsList(); intent.putExtra(NOTIFICATION_EXTRA_INTERACTION_TYPE, interaction.getType().name()); intent.putExtra(NOTIFICATION_EXTRA_INTERACTION_DEFINITION, interaction.toString()); intent.putExtra(NOTIFICATION_EXTRA_NOTE_ACTION_INDEX, i); switch (actionType) { data.put(TextModalInteraction.KEY_DISPLAY_TYPE, interaction.getDisplayType().name()); } catch (JSONException e) { ApptentiveLog.e(NOTIFICATION_INTERACTIONS, e, "Error creating Event data object.");
public String getBody() { try { InteractionConfiguration configuration = getConfiguration(); if (configuration != null && configuration.has(KEY_BODY)) { return configuration.getString(KEY_BODY); } } catch (JSONException e) { logException(e); } return null; }
if (interaction.getTitle() == null) { title.setVisibility(View.GONE); } else { title.setText(interaction.getTitle()); if (interaction.getBody() == null) { body.setVisibility(View.GONE); } else { body.setText(interaction.getBody()); Actions actionsObject = interaction.getActions(); boolean vertical; List<Action> actions = null;
@Test public void textModalInteraction() { String json = loadTextAssetAsString(TEST_DATA_DIR + "/testTextModalInteraction.json"); Interaction interaction = Interaction.Factory.parseInteraction(json); assertTrue(interaction.getType().equals(Interaction.Type.TextModal)); TextModalInteraction textModalInteraction = (TextModalInteraction) interaction; assertEquals("548cc5dd49f63bb5c2000001", textModalInteraction.getId()); assertEquals("External Deep Links", textModalInteraction.getTitle()); assertEquals("This example allow testing how external deep links are opened.", textModalInteraction.getBody()); List<Action> actions = textModalInteraction.getActions().getAsList(); { Action action = actions.get(0); assertEquals("eBay - Same Task", action.getLabel()); assertTrue(action.getType().equals(Action.Type.interaction)); } } }
List<Action> actions = interaction.getActions().getAsList(); final Action action = actions.get(index); Action.Type actionType = action.getType(); data.put(Action.KEY_LABEL, action.getLabel()); data.put(TextModalInteraction.EVENT_KEY_ACTION_POSITION, index); data.put(TextModalInteraction.KEY_DISPLAY_TYPE, interaction.getDisplayType().name()); } catch (JSONException e) { ApptentiveLog.e(NOTIFICATION_INTERACTIONS, e, "Error creating Event data object.");
@Override public void handleInteractionNotificationAction(Context context, String channelId, Intent intent) { String action = intent.getAction(); String interactionString = intent.getStringExtra(NOTIFICATION_EXTRA_INTERACTION_DEFINITION); TextModalInteraction interaction; try { interaction = new TextModalInteraction(intent.getStringExtra(NOTIFICATION_EXTRA_INTERACTION_DEFINITION)); } catch (JSONException e) { ApptentiveLog.w(NOTIFICATION_INTERACTIONS, "Unable to parse interaction: %s", interactionString); logException(e); return; } if (StringUtils.equal(action, NOTIFICATION_ACTION_DISPLAY)) { actionDisplayNotification(context, channelId, interaction); } else if (StringUtils.equal(action, NOTIFICATION_ACTION_DELETE)) { actionDelete(context, interaction); } else if (StringUtils.equal(action, NOTIFICATION_ACTION_NOTE_BUTTON_PRESSED)) { actionButtonPressed(context, intent, interaction); } else { ApptentiveLog.w(NOTIFICATION_INTERACTIONS, "Unsupported action %s for Interaction type %s", action, interaction.getType().name()); } }
protected void actionDelete(final Context context, final TextModalInteraction interaction) { ApptentiveLog.v(NOTIFICATION_INTERACTIONS, "Delete intent received."); final JSONObject data = new JSONObject(); try { data.put(TextModalInteraction.KEY_DISPLAY_TYPE, interaction.getDisplayType().name()); } catch (JSONException e) { ApptentiveLog.e(NOTIFICATION_INTERACTIONS, e, "Error creating Event data object."); logException(e); } dispatchConversationTask(new ConversationDispatchTask() { @Override protected boolean execute(Conversation conversation) { return EngagementModule.engageInternal(context, conversation, interaction, TextModalInteraction.EVENT_NAME_CANCEL, data.toString()); } }, "engage Note Notification cancel"); } }
return new SurveyInteraction(interactionString); case TextModal: return new TextModalInteraction(interactionString); case NavigateToLink: return new NavigateToLinkInteraction(interactionString);
data.put(TextModalInteraction.EVENT_KEY_ACTION_POSITION, index); data.put(TextModalInteraction.EVENT_KEY_INVOKED_INTERACTION_ID, invokedInteraction == null ? JSONObject.NULL : invokedInteraction.getId()); data.put(TextModalInteraction.KEY_DISPLAY_TYPE, interaction.getDisplayType().name()); } catch (JSONException e) { ApptentiveLog.e(NOTIFICATION_INTERACTIONS, e, "Error creating Event data object.");
public String getTitle() { try { InteractionConfiguration configuration = getConfiguration(); if (configuration != null && configuration.has(KEY_TITLE)) { return configuration.getString(KEY_TITLE); } } catch (JSONException e) { logException(e); } return null; }
public Actions getActions() { try { InteractionConfiguration configuration = getConfiguration(); if (configuration != null && configuration.has(KEY_ACTIONS)) { return new Actions(configuration.getString(KEY_ACTIONS)); } } catch (JSONException e) { logException(e); } return null; } }