Java Code Examples for com.google.android.gms.ads.doubleclick.PublisherInterstitialAd#setAdUnitId()

The following examples show how to use com.google.android.gms.ads.doubleclick.PublisherInterstitialAd#setAdUnitId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DemoActivity.java    From prebid-mobile-android with Apache License 2.0 6 votes vote down vote up
private void setupAMInterstitial(String id) {
    amInterstitial = new PublisherInterstitialAd(this);
    amInterstitial.setAdUnitId(id);
    amInterstitial.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
            super.onAdLoaded();
            amInterstitial.show();
        }

        @Override
        public void onAdFailedToLoad(int i) {
            super.onAdFailedToLoad(i);
            AlertDialog.Builder builder;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                builder = new AlertDialog.Builder(DemoActivity.this, android.R.style.Theme_Material_Dialog_Alert);
            } else {
                builder = new AlertDialog.Builder(DemoActivity.this);
            }
            builder.setTitle("Failed to load AdManager interstitial ad")
                    .setMessage("Error code: " + i)
                    .setIcon(android.R.drawable.ic_dialog_alert)
                    .show();
        }
    });
}
 
Example 2
Source File: GooglePlayDFPInterstitial.java    From mobile-sdk-android with Apache License 2.0 5 votes vote down vote up
@Override
public void requestAd(MediatedInterstitialAdViewController mIC, Activity activity,
                      String parameter, String adUnitId, TargetingParameters targetingParameters) {
    adListener = new GooglePlayAdListener(mIC, super.getClass().getSimpleName());
    adListener.printToClog(String.format(" - requesting an ad: [%s, %s]", parameter, adUnitId));

    interstitialAd = new PublisherInterstitialAd(activity);
    interstitialAd.setAdUnitId(adUnitId);
    interstitialAd.setAdListener(adListener);

    interstitialAd.loadAd(buildRequest(targetingParameters));
}
 
Example 3
Source File: MyActivity.java    From android-ads with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my);

    // Create the InterstitialAd and set the adUnitId.
    interstitialAd = new PublisherInterstitialAd(this);
    // Defined in res/values/strings.xml
    interstitialAd.setAdUnitId(AD_UNIT_ID);

    interstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdClosed() {
            startGame();
        }

        @Override
        public void onAdLoaded() {
            adIsLoading = false;
            Toast.makeText(MyActivity.this, "onAdLoaded()", Toast.LENGTH_SHORT).show();

        }

        @Override
        public void onAdFailedToLoad(int errorCode) {
            adIsLoading = false;
            Toast.makeText(MyActivity.this,
                    "onAdFailedToLoad() with error code: " + errorCode,
                    Toast.LENGTH_SHORT).show();
        }
    });

    // Create the "retry" button, which tries to show an interstitial between game plays.
    retryButton = findViewById(R.id.retry_button);
    retryButton.setVisibility(View.INVISIBLE);
    retryButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            showInterstitial();
        }
    });

    startGame();
}
 
Example 4
Source File: MyActivity.java    From googleads-mobile-android-examples with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my);

    // Create the InterstitialAd and set the adUnitId.
    interstitialAd = new PublisherInterstitialAd(this);
    // Defined in res/values/strings.xml
    interstitialAd.setAdUnitId(AD_UNIT_ID);

    interstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdClosed() {
            startGame();
        }

        @Override
        public void onAdLoaded() {
            adIsLoading = false;
            Toast.makeText(MyActivity.this, "onAdLoaded()", Toast.LENGTH_SHORT).show();

        }

        @Override
        public void onAdFailedToLoad(int errorCode) {
            adIsLoading = false;
            Toast.makeText(MyActivity.this,
                    "onAdFailedToLoad() with error code: " + errorCode,
                    Toast.LENGTH_SHORT).show();
        }
    });

    // Create the "retry" button, which tries to show an interstitial between game plays.
    retryButton = findViewById(R.id.retry_button);
    retryButton.setVisibility(View.INVISIBLE);
    retryButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            showInterstitial();
        }
    });

    startGame();
}