Skip to main content

Basic Usage

Add the App Feedback Code​

Set up the Activity​

Open your MainActivity.java file and add the following import statement at the top of the file:

MainActivity.java
import com.qualtrics.digital.*;

Add the following line in the onCreate method:

MainActivity.java
Qualtrics.instance().initializeProject("BRAND_ID", "PROJECT_ID", "EXT_REF_ID", MainActivity.this);

The first few lines of your onCreate method should look like the following:

MainActivity.java
    @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());

setSupportActionBar(binding.toolbar);

NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_content_main);
appBarConfiguration = new AppBarConfiguration.Builder(navController.getGraph()).build();
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);

// Add this line:
Qualtrics.instance().initializeProject("BRAND_ID", "PROJECT_ID", "EXT_REF_ID", MainActivity.this);

Replace BRAND_ID and PROJECT_ID with the Brand ID and Project ID you obtained from the App Feedback project within the Qualtrics Experience Management (XM) platform.

Add a MyCallback Subclass​

You need to implement a callback for the Qualtrics APIs. This will be used to call the displayIntercept() method based on the evaluateIntercept() result. A good place is before the last closing brace } in your MainActivity.java class. Add the following code:

MainActivity.java
import java.util.Map;

private class MyCallback implements IQualtricsProjectEvaluationCallback {
@Override
public void run(Map<String, TargetingResult> targetingResults) {
for (Map.Entry<String,TargetingResult> result: targetingResults.entrySet())
if (result.getValue().passed()) {
Qualtrics.instance().displayIntercept(MainActivity.this, result.getKey());
}
}
}

This callback will be called by the Qualtrics.evaluateProject method once the evaluation is complete.

Lambda Expression​

You can also implement a lambda expression rather than creating a private class that implements the IQualtricsProjectEvaluationCallback interface (in Java 8 and later).

In the onCreate method, you will find autogenerated code like the following:

MainActivity.java
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
binding.fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});

Replace the code within the onClick block with the following:

MainActivity.java
Qualtrics.instance().evaluateProject(new MyCallback());

It should look like the following:

MainActivity.java
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
binding.fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

// Insert this line
Qualtrics.instance().evaluateProject(new MyCallback());

// Comment out or remove the original autogenerated code
//Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
//.setAction("Action", null).show();
}
});