deleteIntent.putExtra(NOTIFICATION_EXTRA_INTERACTION_TYPE, interaction.getType().name()); deleteIntent.putExtra(NOTIFICATION_EXTRA_INTERACTION_DEFINITION, interaction.toString()); deleteIntent.setAction(NOTIFICATION_ACTION_DELETE); 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);
JSONObject interaction = new JSONObject(interactionString); if (interaction.has(KEY_TYPE)) { type = Type.parse(interaction.getString(KEY_TYPE));
@Override public void handleBroadcast(Context context, Intent intent) throws JSONException { ApptentiveLog.d(NOTIFICATION_INTERACTIONS, "Received broadcast"); logIntent(intent); // Set Notification Channel if supported by version if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { ContextUtils.getNotificationManager(context).createNotificationChannel(NotificationChannelHolder.getInstance()); } // Get the interaction to display Interaction.Type interactionType = Interaction.Type.parse(intent.getStringExtra(Constants.NOTIFICATION_EXTRA_INTERACTION_TYPE)); String interactionDefinition = intent.getStringExtra(NOTIFICATION_EXTRA_INTERACTION_DEFINITION); if (interactionDefinition == null) { ApptentiveLog.w("Interaction Notification Intent is missing extra %s", NOTIFICATION_EXTRA_INTERACTION_DEFINITION); return; } InteractionNotificationAdapter interactionNotificationAdapter; switch (interactionType) { case TextModal: interactionNotificationAdapter = DEFAULT_ADAPTER_NOTE; break; default: ApptentiveLog.w("Attempted to launch Interaction as Notification, but that is not supported for the interaction type: %s", interactionDefinition); return; } interactionNotificationAdapter.handleInteractionNotificationAction(context, NOTIFICATION_CHANNEL_DEFAULT, intent); }
@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()); } }
@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)); } } }
public static synchronized boolean engageInternal(Context context, Conversation conversation, Interaction interaction, String eventName) { return engage(context, conversation, "com.apptentive", interaction.getType().name(), interaction.getId(), eventName, null, null, (ExtendedData[]) null); }
@Override public boolean launch(Context context, Interaction interaction) { if (!NotificationUtils.isNotificationChannelEnabled(context, NOTIFICATION_CHANNEL_DEFAULT)) { ApptentiveLog.e(NOTIFICATIONS, "Unable to engage notification interaction: notification channel is disabled"); return false; } final Intent launchIntent = new Intent(context, ApptentiveNotificationInteractionBroadcastReceiver.class); launchIntent.setAction(NOTIFICATION_ACTION_DISPLAY); launchIntent.putExtra(NOTIFICATION_EXTRA_INTERACTION_TYPE, interaction.getType().name()); launchIntent.putExtra(NOTIFICATION_EXTRA_INTERACTION_DEFINITION, interaction.toString()); context.sendBroadcast(launchIntent); return true; } }
public static synchronized boolean engageInternal(Context context, Conversation conversation, Interaction interaction, String eventName, String data) { return engage(context, conversation, "com.apptentive", interaction.getType().name(), interaction.getId(), eventName, data, null, (ExtendedData[]) null); }
public static Type parse(String type) { try { return Type.valueOf(type); } catch (IllegalArgumentException e) { ApptentiveLog.v(INTERACTIONS, "Error parsing unknown Interaction.Type: " + type); logException(e); } return unknown; } }
@Test public void navigateToLinkInteractionMissing() { String json = loadTextAssetAsString(TEST_DATA_DIR + "/testNavigateToLinkInteractionMissing.json"); Interaction interaction = Interaction.Factory.parseInteraction(json); assertTrue(interaction.getType().equals(Interaction.Type.NavigateToLink)); NavigateToLinkInteraction link = (NavigateToLinkInteraction) interaction; assertEquals("http://pages.ebay.com/link/?nav=item.view&id=221648890812", link.getUrl()); assertTrue(link.getTarget().equals(NavigateToLinkInteraction.Target.New)); } }
@Test public void navigateToLinkInteractionSelf() { String json = loadTextAssetAsString(TEST_DATA_DIR + "/testNavigateToLinkInteractionSelf.json"); Interaction interaction = Interaction.Factory.parseInteraction(json); assertTrue(interaction.getType().equals(Interaction.Type.NavigateToLink)); NavigateToLinkInteraction link = (NavigateToLinkInteraction) interaction; assertEquals("http://pages.ebay.com/link/?nav=item.view&id=221648890812", link.getUrl()); assertTrue(link.getTarget().equals(NavigateToLinkInteraction.Target.Self)); }
@Test public void navigateToLinkInteractionNew() { String json = loadTextAssetAsString(TEST_DATA_DIR + "/testNavigateToLinkInteractionNew.json"); Interaction interaction = Interaction.Factory.parseInteraction(json); assertTrue(interaction.getType().equals(Interaction.Type.NavigateToLink)); NavigateToLinkInteraction link = (NavigateToLinkInteraction) interaction; assertEquals("http://pages.ebay.com/link/?nav=item.view&id=221648890812", link.getUrl()); assertTrue(link.getTarget().equals(NavigateToLinkInteraction.Target.New)); }
public Type getType() { try { if (!isNull(KEY_TYPE)) { return Type.parse(getString(KEY_TYPE)); } } catch (JSONException e) { logException(e); } return Type.unknown; }