javaandroidadcolony

How to show Video Ad (AdColony)


I have an application in which I want to integrate VIDEO AD from AdColony.

When the user clicks on the button, the loadAd() method is triggered, and after that onRequestFilled. But after calling show() nothing happens.

Here's class with all methods that i have for AdColony.

public class AdColonyAds {

private  final String ZONE_ID = "vzac61b40e83e8436c9e";
private  final String APP_ID_ADCOLONY = "appa567471ee29646b5b5";
private AdColonyInterstitial ad;
private AdColonyInterstitialListener listener;
private AdColonyAdOptions ad_options;
private String uniqueID;


private Activity activity;

public AdColonyAds(Activity activity) {
    this.activity = activity;
    uniqueID = UUID.randomUUID().toString();
}


public void initAdColony(){
    AdColonyAppOptions app_options = new AdColonyAppOptions()
            .setUserID(uniqueID);

    AdColony.configure( activity, app_options, APP_ID_ADCOLONY, ZONE_ID );

    AdColonyUserMetadata metadata = new AdColonyUserMetadata()
            .setUserAge( 26 )
            .setUserEducation( AdColonyUserMetadata.USER_EDUCATION_BACHELORS_DEGREE )
            .setUserGender( AdColonyUserMetadata.USER_MALE );

    ad_options = new AdColonyAdOptions()
            .enableConfirmationDialog( true )
            .enableResultsDialog( true )
            .setUserMetadata( metadata );

    AdColony.setRewardListener( new AdColonyRewardListener()
    {
        @Override
        public void onReward( AdColonyReward reward )
        {
            reward.getRewardAmount();
        }
    } );

    listener = new AdColonyInterstitialListener() {
        @Override
        public void onRequestFilled(AdColonyInterstitial adColonyInterstitial) {
            Toast.makeText(activity,"Ready",Toast.LENGTH_SHORT).show();
             adColonyInterstitial.show();
        }
    };
}

public void showAdColony(){
    ad.show();
}

public void loadAd(){
    AdColony.requestInterstitial( ZONE_ID, listener, ad_options );
}

}


Solution

  • You may need to set ad instance variable at onRequestFilled listener to use after from showAdColony method.

    listener = new AdColonyInterstitialListener() {
        @Override
        public void onRequestFilled(AdColonyInterstitial adColonyInterstitial) {
            ad = adColonyInterstitial;
        }
    };