Retrieving an Interaction response

The Medallia Experience Orchestration SDK considers Android Activities and Fragments as Interactions. When configured correctly the SDK will automatically send an Interaction request to Medallia Experience Orchestration and process the response which may contain Points (Optimizations, Capture, etc). If desired, you can be notified of these automatic Interactions to take additional action on each Interaction request, by using the automatic Interaction subscription API.

It is incumbent on you to then process the response in order for the Medallia Experience Orchestration SDK to perform automatic Capture and Optimization.

Important: Assigning a manual/custom Interaction to a view should be done before setting an automatic Interaction callback. If you set a callback for an automatically triggered Interaction, you are advised to remove that callback as soon as it is no longer needed under your Activity's onStop method.

The response can be passed to the process method, as shown below. By calling this method the response is returned to the SDK to process, attaching any Captures, Trackers, and/or Optimizations to the Interaction.

This functionality will not work if automatic Interaction detection is disabled. For retrieving the response in sending programmatic Interactions, see sending an Interaction request and retrieve the response.

Retrieving a response for an automatic Activity Interaction request

Kotlin
Java
import com.medallia.mxo.automatic.MXOAutomaticInteractionSubscription import com.medallia.mxo.mxoSubscribeToAutomaticInteraction import com.medallia.mxo.process import android.util.Log class MainActivity : AppCompatActivity() { private var mxoAutomaticInteractionSubscription: MXOAutomaticInteractionSubscription? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) } override fun onStart() { super.onStart() mxoAutomaticInteractionSubscription = mxoSubscribeToAutomaticInteraction { interaction(this@MainActivity) onError { error -> Log.e(TAG, "SDK Error", error) } onFailure { error -> Log.e(TAG, "API Error", error) } onResponse { response -> Log.d(TAG, "Success: ${response.tid}") response.process() } } } override fun onStop() { super.onStop() mxoAutomaticInteractionSubscription?.unsubscribe() } companion object { const val TAG = "MainActivity" } } import com.medallia.mxo.MedalliaMXO; import com.medallia.mxo.automatic.MXOAutomaticInteractionSubscriber; import com.medallia.mxo.automatic.MXOAutomaticInteractionSubscription; import com.medallia.mxo.interactions.MXOInteractionResponse; import com.medallia.mxo.MXOErrorApi; import com.medallia.mxo.MXOErrorSdk; import org.jetbrains.annotations.Nullable; public class MainActivity extends AppCompatActivity { private MXOAutomaticInteractionSubscription mxoAutomaticInteractionSubscription = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Override protected void onStart() { super.onStart(); MXOAutomaticInteractionSubscriber subscriber = new MXOAutomaticInteractionSubscriber.Builder() .interaction(this) .onError(error -> Log.e("example", "SDK Error: " + error.getErrorMessage())) .onFailure(error -> Log.e("example", "API Error: " + error.getErrorMessage())) .onResponse(response -> Log.d("example", response.getTid())) .build(); mxoAutomaticInteractionSubscription = MedalliaMXO.subscribeToAutomaticInteraction(subscriber); } @Override protected void onStop() { super.onStop(); if (mxoAutomaticInteractionSubscription != null) { mxoAutomaticInteractionSubscription.unsubscribe(); } } }

Retrieving a response for an automatic Fragment Interaction request

Kotlin
Java
import com.medallia.mxo.automatic.MXOAutomaticInteractionSubscription import com.medallia.mxo.mxoSubscribeToAutomaticInteraction import com.medallia.mxo.process import android.util.Log class MainActivity : FragmentActivity() { private var mxoAutomaticInteractionSubscription: MXOAutomaticInteractionSubscription? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) if (savedInstanceState == null) { supportFragmentManager.beginTransaction() .add(R.id.fragment_container, TestFragment()) .setReorderingAllowed(true) .commit() } } override fun onStart() { super.onStart() supportFragmentManager .findFragmentById(R.id.fragment_container) mxoAutomaticInteractionSubscription = mxoSubscribeToAutomaticInteraction { interaction(fragment = this@TestFragment) onError { error -> Log.e(TAG, "SDK Error", error) } onFailure { error -> Log.e(TAG, "API Error", error) } onResponse { response -> Log.d(TAG, "Success: ${response.tid}") response.process() } } } override fun onStop() { super.onStop() supportFragmentManager .findFragmentById(R.id.fragment_container) mxoAutomaticInteractionSubscription?.unsubscribe() } class TestFragment : Fragment() { override fun onCreateView ( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? = inflater.inflate(R.layout.fragment_test, container, false) } companion object { const val TAG = "MainActivity" } } import com.medallia.mobile.MedalliaMXO; import com.medallia.mxo.automatic.MXOAutomaticInteractionSubscriber; import com.medallia.mxo.automatic.MXOAutomaticInteractionSubscription; import com.medallia.mxo.interactions.MXOInteractionResponse; import com.medallia.mxo.MXOErrorApi; import com.medallia.mxo.MXOErrorSdk; public class FirstFragment extends Fragment { private FragmentFirstBinding binding; private MXOAutomaticInteractionSubscription mxoSubscription; @Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState ) { binding = FragmentFirstBinding.inflate(inflater, container, false); return binding.getRoot(); } public void onViewCreated(@NonNull View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); binding.buttonFirst.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { NavHostFragment.findNavController(FirstFragment.this) .navigate(R.id.action_FirstFragment_to_SecondFragment); } }); MXOAutomaticInteractionSubscriber subscriber = new MXOAutomaticInteractionSubscriber.Builder() .interaction(this) .onError(error -> Log.e("example", "SDK Error: " + error.getErrorMessage())) .onFailure(error -> Log.e("example", "Api Error: " + error.getErrorMessage())) .onResponse(response -> Log.d("example", response.getTid())) .build(); this.mxoSubscription = MedalliaMXO.subscribeToAutomaticInteraction(subscriber); } @Override public void onDestroyView() { super.onDestroyView(); binding = null; if (this.mxoSubscription != null) { mxoSubscription.unsubscribe(); mxoSubscription = null; } } }

Retrieving a response for a manually assigned Interaction request

Kotlin
Java
import com.medallia.mxo.interactions.MXOInteraction import com.medallia.mxo.process import com.medallia.mxo.automatic.mxoAutomaticInteractionSubscriber import com.medallia.mxo.automatic.mxoAutomaticInteractionSubscribtion import android.util.Log override fun onStart() { super.onStart() mxoAutomaticInteractionSubscription = mxoSubscribeToAutomaticInteraction { interaction(MXOInteraction(URI("/ManualInteraction"))) onError { error -> Log.e(TAG, "SDK Error", error) } onFailure { error -> Log.e(TAG, "API Error", error) } onResponse { response -> Log.d(TAG, "Success: ${response.tid}") response.process() } } } override fun onStop() { super.onStop() mxoAutomaticInteractionSubscription?.unsubscribe() } import com.medallia.mxo.MedalliaMXO; import com.medallia.mxo.interactions.MXOInteraction; import com.medallia.mxo.interactions.MXOInteractionResponse; import com.medallia.mxo.automatic.MXOAutomaticInteractionSubscrber; import com.medallia.mxo.automatic.MXOAutomaticInteractionSubscription; import com.medallia.mxo.MXOErrorApi; import com.medallia.mxo.MXOErrorSdk; import java.net.URI; @Override protected void onStart(){ super.onStart(); MXOAutomaticInteractionSubscriber subscriber = new MXOAutomaticInteractionSubscriber.Builder() .interaction(this) .onError(error -> Log.e("example", "SDK Error: " + error.getErrorMessage())) .onFailure(error -> Log.e("example", "API Error: " + error.getErrorMessage())) .onResponse(response -> Log.d("example", response.getTid())) .build(); mxoAutomaticInteractionSubscription = MedalliaMXO.subscribeToAutomaticInteraction(subscriber); }); } @Override protected void onStop(){ super.onStop(); if (mxoAutomaticInteractionSubscription != null) { mxoAutomaticInteractionSubscription.unsubscribe(); } }