简体   繁体   中英

Admob Interstitial in Android Studio doesn't work

I've tried to insert an Interstitial in myapp but it doesnt'work if i put in oncliklistener and even in the start activity. The build run correctly but the interstitial does not appear, also the alert can't appear.

This is the code:

package com.example.footballplayersquiz2020;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.ads.MobileAds;

public class page3 extends AppCompatActivity

    {
    private SharedPreferences sharedpreferences;

    Integer punteggiofinale = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_page3);

        MobileAds.initialize(getApplicationContext(),
                "ca-app-pub-2704211852861825/3480480517");
        AdView mAdView = (AdView) findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);

        final InterstitialAd interstitialAd;
        interstitialAd = new InterstitialAd(this);
        interstitialAd.setAdUnitId("ca-app-pub-2704211852861825/6611160445");
        interstitialAd.loadAd(new AdRequest.Builder().build());

        //startad
        if (interstitialAd.isLoaded()) {
            interstitialAd.show();
        } else {
            Log.d("TAG", "The interstitial wasn't loaded yet.");
        }

        //end ad

Don't know why the interstitial cant' load.

"ca-app-pub-2704211852861825/3480480517" there must be "~" between numbers instead "/" Check your App ID.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM