4. Call the Inference API
Configure the Airflux SDK to request an inference decision before displaying an interstitial ad. Based on the AI's response, you can decide whether to proceed with showing the ad. This process allows for smarter, more revenue-optimized ad delivery.

1. Set up the API Call and callbacks
Use the Airflux.requestInference() function with the SHOW_INTERSTITIAL_AD method to request a real-time ad decision. To ensure the AI makes an accurate decision, you must provide detailed contextual parameters and implement the appropriate callbacks.
Code Example
import ai.airflux.Airflux
import ai.airflux.AirfluxInference
import ai.airflux.AirfluxParameter
import android.util.Log
Airflux.requestInference(
inference = AirfluxInference.SHOW_INTERSTITIAL_AD(
parameters = mapOf(
AirfluxParameter.AD_TYPE to "interstitial_ad",
AirfluxParameter.AD_PLACEMENT_ID to "placement_3",
AirfluxParameter.AD_PLACEMENT_TYPE to "static",
AirfluxParameter.AD_PLACEMENT_POSITION to "stage_start",
AirfluxParameter.STAGE to 10,
AirfluxParameter.STAGE_TYPE to "primary_stage",
AirfluxParameter.TOTAL_FINISHED_STAGE to 10,
AirfluxParameter.STAGE_RESULT to "success",
AirfluxParameter.AD_COOLDOWN_SECONDS to mapOf(
"rewarded_ad" to 10,
"interstitial_ad" to 20
),
AirfluxParameter.REWARD_ITEMS to mapOf(
"coin" to 500,
"gem" to 10
),
AirfluxParameter.FORCE_RESPONSE to mapOf(
"action" to "showAd",
"parameters" to mapOf<String, Any>()
)
),
onShowAd = {
// AI determined to show the ad. Implement your logic here.
Log.d("Airflux", "AI decided to show ad.")
// Your function to display the interstitial ad
},
onSkipAd = {
// AI determined to skip the ad. Implement your logic here.
Log.d("Airflux", "AI decided to skip ad.")
// Your function to continue gameplay without showing ads
},
onDefaultAdPolicy = {
// Implement your internal logic to decide whether to show or skip the ad.
Log.d("Airflux", "AI returned default policy. Implementing internal logic.")
// Your function for default ad decision logic
},
onFailure = { error ->
// Inference request failed. Implement your internal logic to handle the error
// and decide whether to show or skip the ad based on your game's policy.
Log.e("Airflux", "Inference request failed: ${error.message}. Falling back to default policy.")
// Your function for default ad decision logic on error
}
)
)
import ai.airflux.Airflux;
import ai.airflux.AirfluxInference;
import ai.airflux.AirfluxParameter;
import android.util.Log;
Airflux.requestInference(
AirfluxInference.SHOW_INTERSTITIAL_AD(
new HashMap<String, Object>() {{
put(AirfluxParameter.AD_TYPE, "interstitial_ad");
put(AirfluxParameter.AD_PLACEMENT_ID, "placement_3");
put(AirfluxParameter.AD_PLACEMENT_TYPE, "static");
put(AirfluxParameter.AD_PLACEMENT_POSITION, "stage_start");
put(AirfluxParameter.STAGE, 10);
put(AirfluxParameter.STAGE_TYPE, "primary_stage");
put(AirfluxParameter.TOTAL_FINISHED_STAGE, 10);
put(AirfluxParameter.STAGE_RESULT, "success");
put(AirfluxParameter.AD_COOLDOWN_SECONDS, new HashMap<String, Integer>() {{
put("rewarded_ad", 10);
put("interstitial_ad", 20);
}});
put(AirfluxParameter.REWARD_ITEMS, new HashMap<String, Integer>() {{
put("coin", 500);
put("gem", 10);
}});
put(AirfluxParameter.FORCE_RESPONSE, new HashMap<String, Object>() {{
put("action", "showAd");
put("parameters", new HashMap<String, Object>());
}});
}},
() -> {
// AI determined to show the ad. Implement your logic here.
Log.d("Airflux", "AI decided to show ad.");
// Your function to display the interstitial ad
},
() -> {
// AI determined to skip the ad. Implement your logic here.
Log.d("Airflux", "AI decided to skip ad.");
// Your function to continue gameplay without showing ads
},
() -> {
// Implement your internal logic to decide whether to show or skip the ad.
Log.d("Airflux", "AI returned default policy. Implementing internal logic.");
// Your function for default ad decision logic
},
airfluxError -> {
// Inference request failed. Implement your internal logic to handle the error
// and decide whether to show or skip the ad based on your game's policy.
Log.e("Airflux", String.format("Inference request failed: %s. Falling back to default policy.", airfluxError.getMessage()));
// Your function for default ad decision logic on error
}
)
);
Verification
2. Deploy the app
After completing sufficient QA and crash testing, deploy your gaming app. To ensure proper integration with Airflux, make sure the deployment follows the timeline coordinated with the Growth Manager.
Next steps
Congratulations! If you have completed the steps above, you are all set to optimize your in-game advertising with Airflux. Click here to learn how to receive your optimization results.
Frequently Asked Questions
Last updated

