Android 安卓插播广告不显示

Android 安卓插播广告不显示,android,admob,Android,Admob,我有一个没有显示的插播广告问题。 这是我想展示广告的活动 import android.content.Intent; import android.graphics.Typeface; import android.os.Bundle; import android.os.Handler; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.Gravity;

我有一个没有显示的插播广告问题。 这是我想展示广告的活动

import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import com.enjoyyourriding.example.diana.mountainbikequest.DbHelper.DbHelper;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.InterstitialAd;

import static com.enjoyyourriding.example.diana.mountainbikequest.R.id.txtTotalScore;

public class Done extends AppCompatActivity {
    Button btnTryAgain;
    TextView txtResultScore, txtResultQuestions;
    ProgressBar progressBarResult;
private InterstitialAd interstitialAd;
    final String TAG = this.getClass().getName();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_done);
        AdView adview = (AdView) findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build();
        adview.loadAd(adRequest);

        interstitialAd = new InterstitialAd(this);
        interstitialAd.setAdUnitId("ca-app-pub-6594925022395892/2492722367");
        interstitialAd.loadAd(adRequest);
        Typeface mytupeface = Typeface.createFromAsset(getAssets(), "Helveticrap.ttf");
        TextView myTextView = (TextView) findViewById(R.id.textView);
        myTextView.setTypeface(mytupeface);
        DbHelper db = new DbHelper(this);
        btnTryAgain = (Button) findViewById(R.id.btnTryAgain);
        txtResultScore = (TextView) findViewById(txtTotalScore);
        txtResultQuestions = (TextView) findViewById(R.id.txttotalQuestions);
        btnTryAgain.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getApplicationContext(), MainActivity.class);
                startActivity(intent);

                finish();
            }

        });

        adview.setAdListener(new AdListener() {
            @Override
            public void onAdLoaded() {
                // Code to be executed when an ad finishes loading.
            }



            @Override
            public void onAdOpened() {
                // Code to be executed when an ad opens an overlay that
                // covers the screen.
            }

            @Override
            public void onAdLeftApplication() {
                finish();
            }

            @Override
            public void onAdClosed() {
                super.onAdClosed();
            }
        });

        Bundle extra = getIntent().getExtras();
        if (extra != null) {
            int score = extra.getInt("SCORE");
            int totalQuestions = extra.getInt("TOTAL");
            int correctAnswer = extra.getInt("CORRECT");
            txtResultScore.setText(String.format("SCORE : %d", score));
            txtResultQuestions.setText(String.format("PASSED : %d/%d", correctAnswer, totalQuestions));

            if (score == 225) {
                LayoutInflater inflater = getLayoutInflater();

                View layout = inflater.inflate(R.layout.custommessage5,
                        (ViewGroup) findViewById(R.id.custommessage5));

                TextView text = (TextView) layout.findViewById(R.id.textView8);
                text.setText("You are one of the best!");

                for (int i = 0; i < 2; i++) {

                    Toast toast = new Toast(getApplicationContext());
                    toast.setGravity(Gravity.CENTER, 0, 0);
                    toast.setDuration(Toast.LENGTH_LONG);
                    toast.setView(layout);
                    toast.show();
                    db.insertScore(score);
                }
            }else if (score == 250) {
                LayoutInflater inflater = getLayoutInflater();

                View layout = inflater.inflate(R.layout.custommessage6,
                        (ViewGroup) findViewById(R.id.custommessage6));

                TextView text = (TextView) layout.findViewById(R.id.textView8);
                text.setText("You are true mountain bike legend!");

                for (int i = 0; i < 2; i++) {

                    Toast toast = new Toast(getApplicationContext());
                    toast.setGravity(Gravity.CENTER, 0, 0);
                    toast.setDuration(Toast.LENGTH_LONG);
                    toast.setView(layout);

                    toast.show();
                    db.insertScore(score);


                }

            }else if (score == 200) {
                LayoutInflater inflater = getLayoutInflater();

                View layout = inflater.inflate(R.layout.custommessage4,
                        (ViewGroup) findViewById(R.id.custommessage4));

                TextView text = (TextView) layout.findViewById(R.id.textView8);
                text.setText("Well done, you passed 200 questions!");

                for (int i = 0; i < 2; i++) {

                    Toast toast = new Toast(getApplicationContext());
                    toast.setGravity(Gravity.CENTER, 0, 0);
                    toast.setDuration(Toast.LENGTH_LONG);
                    toast.setView(layout);

                    toast.show();
                    db.insertScore(score);
                }

            }else if (score == 170) {
                LayoutInflater inflater = getLayoutInflater();

                View layout = inflater.inflate(R.layout.custommessage7,
                        (ViewGroup) findViewById(R.id.custommessage7));

                TextView text = (TextView) layout.findViewById(R.id.textView8);
                text.setText("Well done, you passed 170 questions!");

                for (int i = 0; i < 2; i++) {

                    Toast toast = new Toast(getApplicationContext());
                    toast.setGravity(Gravity.CENTER, 0, 0);
                    toast.setDuration(Toast.LENGTH_LONG);
                    toast.setView(layout);

                    toast.show();
                    db.insertScore(score);
                }
            }else if (score == 140) {
                LayoutInflater inflater = getLayoutInflater();

                View layout = inflater.inflate(R.layout.custommessage3,
                        (ViewGroup) findViewById(R.id.custommessage3));

                TextView text = (TextView) layout.findViewById(R.id.textView7);
                text.setText("Congratulations, you passed 140 questions!");

                for (int i = 0; i < 2; i++) {

                    Toast toast = new Toast(getApplicationContext());
                    toast.setGravity(Gravity.CENTER, 0, 0);
                    toast.setDuration(Toast.LENGTH_LONG);
                    toast.setView(layout);

                    toast.show();
                    db.insertScore(score);
                }

            }else if (score == 110) {
                LayoutInflater inflater = getLayoutInflater();

                View layout = inflater.inflate(R.layout.custommessage8,
                        (ViewGroup) findViewById(R.id.custommessage8));

                TextView text = (TextView) layout.findViewById(R.id.textView7);
                text.setText("Congratulations, you passed 110 questions!");


                Toast toast = new Toast(getApplicationContext());
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.setDuration(Toast.LENGTH_LONG);
                toast.setView(layout);

                toast.show();
                db.insertScore(score);


            }else if (score == 30) {
                LayoutInflater inflater = getLayoutInflater();

                View layout = inflater.inflate(R.layout.customtoast,
                        (ViewGroup) findViewById(R.id.customtoast));

                TextView text = (TextView) layout.findViewById(R.id.textView5);
                text.setText("Congratulations, you passed 30 questions!");
                for (int i = 0; i < 2; i++) {

                    Toast toast = new Toast(getApplicationContext());
                    toast.setGravity(Gravity.CENTER, 0, 0);
                    toast.setDuration(Toast.LENGTH_LONG);
                    toast.setView(layout);

                    toast.show();
                    db.insertScore(score);

                }
            }else if (score == 50) {
                LayoutInflater inflater = getLayoutInflater();

                View layout = inflater.inflate(R.layout.custommessage9,
                        (ViewGroup) findViewById(R.id.custommessage9));

                TextView text = (TextView) layout.findViewById(R.id.textView7);
                text.setText("Congratulations, you passed 50 questions!");

                for (int i = 0; i < 2; i++) {

                    Toast toast = new Toast(getApplicationContext());
                    toast.setGravity(Gravity.CENTER, 0, 0);
                    toast.setDuration(Toast.LENGTH_LONG);
                    toast.setView(layout);

                    toast.show();
                    db.insertScore(score);
                }

            }else if (score == 80) {
                LayoutInflater inflater = getLayoutInflater();

                View layout = inflater.inflate(R.layout.custommessage2,
                        (ViewGroup) findViewById(R.id.custommessage2));

                TextView text = (TextView) layout.findViewById(R.id.textView6);
                text.setText("Congratulations, you passed 80 questions!");

                for (int i = 0; i < 2; i++) {

                    Toast toast = new Toast(getApplicationContext());
                    toast.setGravity(Gravity.CENTER, 0, 0);
                    toast.setDuration(Toast.LENGTH_LONG);
                    toast.setView(layout);

                    toast.show();
                    db.insertScore(score);
                }

            }
            else if(score>=51&& score <=70  ){
               if (interstitialAd.isLoaded()){
                   interstitialAd.show();
               }
                interstitialAd.loadAd(adRequest);

            }


            db.insertScore(score);
        }
    }

    boolean twice;

    @Override
    public void onBackPressed() {

        Log.d(TAG, "click");

        if(twice==true){
            Intent i = new Intent(Intent.ACTION_MAIN);
            i.addCategory(Intent.CATEGORY_HOME);
            i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(i);
            finish();


        }
        twice = true;
        Log.d(TAG, "twice:" + twice);

        Toast.makeText(Done.this,"Please press BACK again to exit the application",Toast.LENGTH_LONG).show();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                twice = false;
                Log.d(TAG, "twice:" + twice);
            }
        }, 3000);

    }

    }
导入android.content.Intent;
导入android.graphics.Typeface;
导入android.os.Bundle;
导入android.os.Handler;
导入android.support.v7.app.AppActivity;
导入android.util.Log;
导入android.view.Gravity;
导入android.view.LayoutInflater;
导入android.view.view;
导入android.view.ViewGroup;
导入android.widget.Button;
导入android.widget.ProgressBar;
导入android.widget.TextView;
导入android.widget.Toast;
导入com.enjoyyourriding.example.diana.mountainbikequest.DbHelper.DbHelper;
导入com.google.android.gms.ads.AdListener;
导入com.google.android.gms.ads.AdRequest;
导入com.google.android.gms.ads.AdView;
导入com.google.android.gms.ads.alad;
导入静态com.enjoyyourriding.example.diana.mountainbikequest.R.id.txtotalscore;
公共类已完成扩展AppCompative活动{
按钮btnTryAgain;
TextView txtResultCore、txtResultQuestions;
ProgressBar progressBarResult;
私人间质;
最后一个字符串标记=this.getClass().getName();
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_done);
AdView AdView=(AdView)findViewById(R.id.AdView);
AdRequest AdRequest=新建AdRequest.Builder().addTestDevice(AdRequest.DEVICE\u ID\u EMULATOR.build();
adview.loadAd(adRequest);
Interstitalad=新的Interstitalad(本);
间质性setAdUnitId(“ca-app-pub-6594925022395892/2492722367”);
间质负荷(adRequest);
Typeface mytupeface=Typeface.createFromAsset(getAssets(),“Helveticrap.ttf”);
TextView myTextView=(TextView)findViewById(R.id.TextView);
设置字体(mytupeface);
DbHelper db=新的DbHelper(this);
btnTryAgain=(按钮)findViewById(R.id.btnTryAgain);
txtResultScore=(TextView)findViewById(txtTotalScore);
txtResultQuestions=(TextView)findViewById(R.id.txttotalQuestions);
btnTryAgain.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
Intent Intent=新的Intent(getApplicationContext(),MainActivity.class);
星触觉(意向);
完成();
}
});
adview.setAdListener(新的AdListener(){
@凌驾
已加载的公共无效(){
//ad完成加载时要执行的代码。
}
@凌驾
公开作废{
//当广告打开覆盖时要执行的代码
//覆盖屏幕。
}
@凌驾
onAdLeftApplication()上的公共无效{
完成();
}
@凌驾
已关闭的()上的公共无效{
super.onAdClosed();
}
});
Bundle extra=getIntent().getExtras();
如果(额外!=null){
int score=extra.getInt(“分数”);
int totalQuestions=extra.getInt(“总计”);
int correctAnswer=extra.getInt(“CORRECT”);
TXTRULTSCORE.setText(String.format(“分数:%d”,分数));
txtResultQuestions.setText(String.format(“传递:%d/%d”,正确答案,totalQuestions));
如果(分数=225){
LayoutInflater充气机=getLayoutInflater();
视图布局=充气机。充气(R.layout.custommessage5,
(ViewGroup)findViewById(R.id.custommessage5));
TextView text=(TextView)layout.findViewById(R.id.textView8);
setText(“你是最棒的!”;
对于(int i=0;i<2;i++){
Toast Toast=新Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER,0,0);
toast.setDuration(toast.LENGTH\u LONG);
toast.setView(布局);
toast.show();
db.insertScore(分数);
}
}否则如果(分数=250){
LayoutInflater充气机=getLayoutInflater();
视图布局=充气机。充气(R.layout.custommessage6,
(ViewGroup)findViewById(R.id.custommessage6));
TextView text=(TextView)layout.findViewById(R.id.textView8);
setText(“你是真正的山地车传奇人物!”);
对于(int i=0;i<2;i++){
Toast Toast=新Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER,0,0);
toast.setDuration(toast.LENGTH\u LONG);
toast.setView(布局);
toast.show();
db.insertScore(分数);
}
}否则如果(分数=200){
LayoutInflater充气机=getLayoutInflater();
视图布局=充气机。充气(R.layout.custommessage4,
(ViewGroup)findViewById(R.id.custommessage4));
TextView text=(TextView)layout.findViewById(R.id.textView8);
setText(“干得好,你通过了200个问题!”);
对于(int i=0;i<2;i++){
Toast Toast=新Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER,0,0);
toast.setDuration(toast.LENGTH\u LONG);
toast.setView(布局);
toast.show();
db.insertScore(分数);
}
}否则如果(分数=170){
LayoutInflater充气机=getLayoutInflater();
视图布局=充气机。充气(R.layout.custommessage7,
(Vie)