Search in sources :

Example 1 with VideoInterstitialAdUnit

use of org.prebid.mobile.VideoInterstitialAdUnit in project prebid-mobile-android by prebid.

the class RubiconInterstitialVideoGamDemoActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_demo);
    PrebidMobile.setPrebidServerHost(Host.RUBICON);
    PrebidMobile.setPrebidServerAccountId(Constants.PBS_ACCOUNT_ID_RUBICON);
    PrebidMobile.setStoredAuctionResponse(Constants.PBS_STORED_RESPONSE_VAST_RUBICON);
    VideoBaseAdUnit.Parameters parameters = new VideoBaseAdUnit.Parameters();
    parameters.setMimes(Arrays.asList("video/mp4"));
    parameters.setProtocols(Arrays.asList(Signals.Protocols.VAST_2_0));
    // parameters.setProtocols(Arrays.asList(new Signals.Protocols(2)));
    parameters.setPlaybackMethod(Arrays.asList(Signals.PlaybackMethod.AutoPlaySoundOff));
    // parameters.setPlaybackMethod(Arrays.asList(new Signals.PlaybackMethod(2)));
    VideoInterstitialAdUnit adUnit = new VideoInterstitialAdUnit("1001-1");
    adUnit.setParameters(parameters);
    this.adUnit = adUnit;
    int millis = getIntent().getIntExtra(Constants.AUTO_REFRESH_NAME, 0);
    adUnit.setAutoRefreshPeriodMillis(millis);
    final AdManagerAdRequest.Builder builder = new AdManagerAdRequest.Builder();
    adUnit.fetchDemand(builder, new OnCompleteListener() {

        @Override
        public void onComplete(ResultCode resultCode) {
            AdManagerAdRequest request = builder.build();
            AdManagerInterstitialAd.load(RubiconInterstitialVideoGamDemoActivity.this, Constants.DFP_VAST_ADUNIT_ID_RUBICON, request, new AdManagerInterstitialAdLoadCallback() {

                @Override
                public void onAdLoaded(@NonNull AdManagerInterstitialAd adManagerInterstitialAd) {
                    super.onAdLoaded(adManagerInterstitialAd);
                    adManagerInterstitialAd.show(RubiconInterstitialVideoGamDemoActivity.this);
                }

                @Override
                public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
                    super.onAdFailedToLoad(loadAdError);
                    AlertDialog.Builder builder;
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                        builder = new AlertDialog.Builder(RubiconInterstitialVideoGamDemoActivity.this, android.R.style.Theme_Material_Dialog_Alert);
                    } else {
                        builder = new AlertDialog.Builder(RubiconInterstitialVideoGamDemoActivity.this);
                    }
                    builder.setTitle("Failed to load AdManager interstitial ad").setMessage("Error: " + loadAdError.toString()).setIcon(android.R.drawable.ic_dialog_alert).show();
                }
            });
        }
    });
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) LoadAdError(com.google.android.gms.ads.LoadAdError) VideoInterstitialAdUnit(org.prebid.mobile.VideoInterstitialAdUnit) AdManagerInterstitialAdLoadCallback(com.google.android.gms.ads.admanager.AdManagerInterstitialAdLoadCallback) AdManagerInterstitialAd(com.google.android.gms.ads.admanager.AdManagerInterstitialAd) OnCompleteListener(org.prebid.mobile.OnCompleteListener) NonNull(androidx.annotation.NonNull) VideoBaseAdUnit(org.prebid.mobile.VideoBaseAdUnit) AdManagerAdRequest(com.google.android.gms.ads.admanager.AdManagerAdRequest) ResultCode(org.prebid.mobile.ResultCode)

Example 2 with VideoInterstitialAdUnit

use of org.prebid.mobile.VideoInterstitialAdUnit in project prebid-mobile-android by prebid.

the class RubiconInterstitialVideoMoPubDemoActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_demo);
    PrebidMobile.setPrebidServerHost(Host.RUBICON);
    PrebidMobile.setPrebidServerAccountId(Constants.PBS_ACCOUNT_ID_RUBICON);
    PrebidMobile.setStoredAuctionResponse(Constants.PBS_STORED_RESPONSE_VAST_RUBICON);
    VideoBaseAdUnit.Parameters parameters = new VideoBaseAdUnit.Parameters();
    parameters.setMimes(Arrays.asList("video/mp4"));
    parameters.setProtocols(Arrays.asList(Signals.Protocols.VAST_2_0));
    // parameters.setProtocols(Arrays.asList(new Signals.Protocols(2)));
    parameters.setPlaybackMethod(Arrays.asList(Signals.PlaybackMethod.AutoPlaySoundOff));
    // parameters.setPlaybackMethod(Arrays.asList(new Signals.PlaybackMethod(2)));
    VideoInterstitialAdUnit adUnit = new VideoInterstitialAdUnit("1001-1");
    adUnit.setParameters(parameters);
    this.adUnit = adUnit;
    final MoPubInterstitial mpInterstitial = new MoPubInterstitial(this, Constants.MOPUB_INTERSTITIAL_VIDEO_ADUNIT_ID_RUBICON);
    mpInterstitial.setInterstitialAdListener(new MoPubInterstitial.InterstitialAdListener() {

        @Override
        public void onInterstitialLoaded(MoPubInterstitial interstitial) {
            interstitial.show();
        }

        @Override
        public void onInterstitialFailed(MoPubInterstitial interstitial, MoPubErrorCode errorCode) {
            AlertDialog.Builder builder;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                builder = new AlertDialog.Builder(RubiconInterstitialVideoMoPubDemoActivity.this, android.R.style.Theme_Material_Dialog_Alert);
            } else {
                builder = new AlertDialog.Builder(RubiconInterstitialVideoMoPubDemoActivity.this);
            }
            builder.setTitle("Failed to load MoPub interstitial ad").setMessage("Error code: " + errorCode.toString()).setIcon(android.R.drawable.ic_dialog_alert).show();
        }

        @Override
        public void onInterstitialShown(MoPubInterstitial interstitial) {
        }

        @Override
        public void onInterstitialClicked(MoPubInterstitial interstitial) {
        }

        @Override
        public void onInterstitialDismissed(MoPubInterstitial interstitial) {
        }
    });
    int millis = getIntent().getIntExtra(Constants.AUTO_REFRESH_NAME, 0);
    adUnit.setAutoRefreshPeriodMillis(millis);
    adUnit.fetchDemand(mpInterstitial, new OnCompleteListener() {

        @Override
        public void onComplete(ResultCode resultCode) {
            mpInterstitial.load();
        }
    });
}
Also used : MoPubErrorCode(com.mopub.mobileads.MoPubErrorCode) OnCompleteListener(org.prebid.mobile.OnCompleteListener) MoPubInterstitial(com.mopub.mobileads.MoPubInterstitial) VideoInterstitialAdUnit(org.prebid.mobile.VideoInterstitialAdUnit) VideoBaseAdUnit(org.prebid.mobile.VideoBaseAdUnit) ResultCode(org.prebid.mobile.ResultCode)

Aggregations

OnCompleteListener (org.prebid.mobile.OnCompleteListener)2 ResultCode (org.prebid.mobile.ResultCode)2 VideoBaseAdUnit (org.prebid.mobile.VideoBaseAdUnit)2 VideoInterstitialAdUnit (org.prebid.mobile.VideoInterstitialAdUnit)2 NonNull (androidx.annotation.NonNull)1 AlertDialog (androidx.appcompat.app.AlertDialog)1 LoadAdError (com.google.android.gms.ads.LoadAdError)1 AdManagerAdRequest (com.google.android.gms.ads.admanager.AdManagerAdRequest)1 AdManagerInterstitialAd (com.google.android.gms.ads.admanager.AdManagerInterstitialAd)1 AdManagerInterstitialAdLoadCallback (com.google.android.gms.ads.admanager.AdManagerInterstitialAdLoadCallback)1 MoPubErrorCode (com.mopub.mobileads.MoPubErrorCode)1 MoPubInterstitial (com.mopub.mobileads.MoPubInterstitial)1