Skip to main content

Test the SDK

Running the App​

When you run the app on the emulator, you will see a screen similar to the following:

app-start

Tap on the button (with an envelope icon), and you should see the creative prompt as shown below:

Creative Pop-Up

Tap on Provide Feedback to take the survey that is associated with your intercept. An example survey is shown below:

Survey

Finally, after you have taken the survey, the intercept concludes as shown in the following screen capture:

End Of Survey Message

Display a Second Intercept​

Now that we've set up a button to display an intercept in our project, let's go ahead and make a second button, which will call an intercept directly via its ID, without having to reinitialize the Qualtrics singleton. This is a key feature provided by version 2.0.0 or newer, allowing for better control over intercept presentation.

Add New Button to MainActivity​

In your res > layout directory, open the activity_main.xml file:

activity_main

Click and drag a new button into the frame as shown below:

secondButton

In your MainActivity.java file, add the following import statement:

MainActivity.java
import android.widget.Button;

Then, after your existing Qualtrics.instance().evaluateProject call, add the following block of code:

MainActivity.java
import android.util.Log;

Button secondButton = (Button) findViewById(R.id.button);
secondButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Qualtrics.instance().evaluateIntercept("InterceptID", new IQualtricsCallback(){
@Override
public void run(TargetingResult targetingResult) {
if (targetingResult.passed()) {
Qualtrics.instance().displayIntercept(MainActivity.this, "InterceptID");
} else if (targetingResult.getTargetingResultStatus() != null) {
if (targetingResult.getError() != null) {
Log.v("Qualtrics", targetingResult.getError().getMessage());
} else {
Log.v("Qualtrics", targetingResult.getTargetingResultStatus().toString());
}
}

}
});
}
});

Your onCreate method should look something like this:

MainActivity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Qualtrics.instance().setLogLevel(QualtricsLogLevel.INFO);
Qualtrics.instance().initializeProject("BRAND_ID", "PROJECT_ID", "EXT_REF_ID", this);


FloatingActionButton fab = findViewById(R.id.fab);
binding.fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Qualtrics.instance().evaluateTargetingLogic(new MyCallback());
}
});

Button secondButton = (Button) findViewById(R.id.button);
secondButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Qualtrics.instance().evaluateIntercept("InterceptID", new IQualtricsCallback(){
@Override
public void run(TargetingResult targetingResult) {
if (targetingResult.passed()) {
Qualtrics.instance().displayIntercept(MainActivity.this, "InterceptID");
} else if (targetingResult.getTargetingResultStatus() != null) {
if (targetingResult.getError() != null) {
Log.v("Qualtrics", targetingResult.getError().getMessage());
} else {
Log.v("Qualtrics", targetingResult.getTargetingResultStatus().toString());
}
}

}
});
}
});
}

Run the App Again​

Now restart the app and select your second button. When you click the second button you created, you should see the second intercept, its creative, and ultimately its survey.