Assigning an Interaction
The SDK automatically assigns an Interaction path to each Android Activity and Fragment. To override the Interaction path that is created automatically, call the mxoAssignAutomaticInteraction
Kotlin extension function or the MedalliaMXO.assignAutomaticInteraction
Java method with a desired Interaction path, as shown below:
import com.medallia.mxo.mxoAssignAutomaticInteraction
import com.medallia.mxo.interactions.MXOInteraction
import java.net.URI
// Activity example.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView<ActivityGardenBinding>(this, R.layout.activity_garden)
mxoAssignAutomaticInteraction {
this.view = findViewById(R.id.example_id)
interaction = MXOInteraction(URI("/InteractionPath"))
}
}
// Fragment example.
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
mxoAssignAutomaticInteraction {
this.view = view
interaction = MXOInteraction(URI("/InteractionPath"))
}
}
import com.medallia.mxo.MedalliaMXO;
import com.medallia.mxo.interactions.MXOInteraction;
import com.medallia.mxo.automatic.MXOAutomaticInteractionAssignment;
import java.net.URI;
// Activity example.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout linearLayout = findViewById(R.id.example_id);
final MXOAutomaticInteractionAssignment mxoAutomaticInteractionAssignment = new MXOAutomaticInteractionAssignment.Builder()
.view(linearLayout)
.interaction(new MXOInteraction(URI.create("/InteractionPath")))
.build();
MedalliaMXO.assignAutomaticInteraction(mxoAutomaticInteractionAssignment);
}
// Fragment example.
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
final MXOAutomaticInteractionAssignment mxoAutomaticInteractionAssignment = new MXOAutomaticInteractionAssignment.Builder()
.view(view)
.interaction(new MXOInteraction(URI.create("/InteractionPath")))
.build();
MedalliaMXO.assignAutomaticInteraction(mxoAutomaticInteractionAssignment);
}
/
and only contains letters, numbers and/or dashes.This can be useful in the following cases:
If an activity with the same layout implements generic functionality and is used to represent various Interactions within the same application. For example, you may have a list view, that is reused across the application to display branch locations in one use case and cash point locations in a second use case.
import com.medallia.mxo.assignAutomaticInteraction import com.medallia.mxo.interactions.MXOInteraction import java.net.URI class LocationsList : ListActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val interaction = if (presenterType == CASH_POINT_LOCATION) { "/cashPointList" } else { "/branchList" } getListView().assignAutomaticInteraction(MXOInteraction(URI(interaction))) } }
import com.medallia.mxo.MedalliaMXO; import com.medallia.mxo.MXOInteraction; import com.medallia.mxo.automatic.MXOAutomaticInteractionAssignment; import java.net.URI; public class LocationsList extends ListActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final MXOAutomaticInteractionAssignment.Builder assignmentBuilder = new MXOAutomaticInteractionAssignment.Builder() .view(getListView()); if (presenterType == CASH_POINT_LOCATION) { assignmentBuilder .interaction(new MXOInteraction(URI.create("/cashPointList"))); } else { assignmentBuilder .interaction(new MXOInteraction(URI.create("/branchList"))); } MedalliaMXO.assignAutomaticInteraction(assignmentBuilder.build()); } }
If a fragment implements generic functionality and may represent various Interactions. For example, in one case it may show a screen containing laptops and, in another, a screen containing cameras.
import com.medallia.mxo.mxoAssignAutomaticInteraction import com.medallia.mxo.interactions.MXOInteraction import java.net.URI fun onCreateView ( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { val view: View = inflater.inflate(R.layout.products_tiles_view, container, false) mxoAssignAutomaticInteraction { this.view = view this.interaction = if (category == Product.Category.LAPTOP) { MXOInteraction(URI.create("/laptopsList")) } else if (category == Product.Category.CAMERA) { MXOInteraction(URI.create("/camerasList")) } else { null } } return view }
import com.medallia.mxo.MedalliaMXO; import com.medallia.mxo.MXOInteraction; import com.medallia.mxo.automatic.MXOAutomaticInteractionAssignment; import java.net.URI; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.products_tiles_view, container, false); final MXOAutomaticInteractionAssignment.Builder assignmentBuilder = new MXOAutomaticInteractionAssignment.Builder() .view(view); if (category == Product.Category.LAPTOP) { assignmentBuilder .interaction(new MXOInteraction(URI.create("/laptopsList"))); } else if (category == Product.Category.CAMERA) { assignmentBuilder .interaction(new MXOInteraction(URI.create("/camerasList"))); } MedalliaMXO.assignAutomaticInteraction(assignmentBuilder.build()); return view; }
If an Interaction is represented by a custom view.
import com.medallia.mxo.mxoaAsignAutomaticInteraction import com.medallia.mxo.interactions.MXOInteraction import java.net.URI fun showVariants() { if (varientsView == null) { variantsView = inflater.inflate(R.layout.variants_slide, mainPanelView, false) variantsView.mxoAssignAutomaticInteraction(MXOInteraction(URI("/variants"))) } }
import com.medallia.mxo.MedalliaMXO; import com.medallia.mxo.MXOInteraction; import com.medallia.mxo.automatic.MXOAutomaticInteractionAssignment; import java.net.URI; void showVariants() { if (variantsView == null) { variantsView = inflater.inflate(R.layout.variants_slide, mainPaneView, false); final MXOAutomaticInteractionAssignment assignment = new MXOAutomaticInteractionAssignment.Builder() .view(variantsView) .interaction(new MXOInteraction(URI.create("/variants"))) .build(); MedalliaMXO.assignAutomaticInteraction(assignment); } }