首页 > java > Admob视频广告加载但未显示

Admob视频广告加载但未显示 (Admob Video ads loading but aren't displaying)

问题

我知道这些视频正在加载,因为吐司的消息弹出来说它确实如此,并且视频在昨天我第一次测试时显示,但现在已经整整一天,但它们仍然无法显示。没有错误,没有崩溃。

package com.example.matthew.myapplication;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.reward.RewardItem;
import com.google.android.gms.ads.reward.RewardedVideoAd;
import com.google.android.gms.ads.reward.RewardedVideoAdListener;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;



public class createGame extends Activity implements RewardedVideoAdListener {
    private Button make;
    private EditText iDd, nam;
    DatabaseReference myRef;
    DataSnapshot datas;
    boolean canGo = false;
    private RewardedVideoAd mAd;

    protected void onCreate(Bundle savedInstanceState) {

        mAd = MobileAds.getRewardedVideoAdInstance(this);
        mAd.setRewardedVideoAdListener(this);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.creategame);
        Intent task = getIntent();
        addListenerOnButton();
        myRef = FirebaseDatabase.getInstance().getReference();
        ValueEventListener postListener = new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                datas = dataSnapshot;
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        };
        myRef.addValueEventListener(postListener);
        loadRewardedVideoAd();
    }


    public void addListenerOnButton() {


        make = (Button) findViewById(R.id.done);
        nam = (EditText) findViewById(R.id.nam);
        iDd = (EditText) findViewById(R.id.makeId);


        make.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                if (mAd.isLoaded()) {
                    mAd.show();
                    Log.d("Here is a test spot", "showing!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); //this log messagr also comes up confirming the ad is loaded bht it doesn't show for whatever reason
                }

                    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
                    String iDD = user.getUid();
                    String gameId = iDd.getText().toString();
                    myRef.child(gameId).child("DM").setValue(iDD);
                    int check2 = 0;
                    boolean done2 = false;
                    while (done2 == false) {
                        String sCheck2 = Integer.toString(check2);
                        if (datas.child(iDD).child("Game List").hasChild(sCheck2)) {
                            check2 = check2 + 1;
                            Log.d("Here is a test spot", "Made it here. 3");
                        } else {
                            myRef.child(iDD).child("Game List").child(sCheck2).setValue(gameId);
                            done2 = true;
                            Log.d("Here is a test spot", "Made it here. 4");
                        }
                    }
                    myRef.child(gameId).child("GAMEID").setValue(gameId);
                    myRef.child(gameId).child("GAME NAME").setValue(nam.getText().toString());
                    myRef.child(gameId).child("Events").child("0").setValue("Game Created.");
                    myRef.child(gameId).child("MRE").setValue("Game Created.");
                    myRef.child(gameId).child("Current Player").setValue("None");
                    myRef.child(gameId).child("pResponse").setValue("No Response Yet");
                    Intent TaskIntent = new Intent(getApplicationContext(), MainScreen.class);
                    startActivity(TaskIntent);
                    finish();

            }
        });

    }

    private void loadRewardedVideoAd() {
        mAd.loadAd("ca-app-pub-3940256099942544/5224354917", new AdRequest.Builder().build());
    }

    @Override
    public void onRewarded(RewardItem reward) {
        canGo = true;
    }

    // The following listener methods are optional.
    @Override
    public void onRewardedVideoAdLeftApplication() {
        Toast.makeText(this, "onRewardedVideoAdLeftApplication",
                Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onRewardedVideoAdClosed() {
        Toast.makeText(this, "onRewardedVideoAdClosed", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onRewardedVideoAdFailedToLoad(int errorCode) {
        Toast.makeText(this, "onRewardedVideoAdFailedToLoad", Toast.LENGTH_LONG).show();
        Log.d("ERROR", Integer.toString(errorCode));
    }

    @Override
    public void onRewardedVideoAdLoaded() {
        Toast.makeText(this, "onRewardedVideoAdLoaded", Toast.LENGTH_LONG).show();
    }

    @Override
    public void onRewardedVideoAdOpened() {
        Toast.makeText(this, "onRewardedVideoAdOpened", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onRewardedVideoStarted() {
        Toast.makeText(this, "onRewardedVideoStarted", Toast.LENGTH_SHORT).show();
    }
}

有我的代码,它没关系,但我仍然不明白为什么广告不会显示。非常感谢任何帮助,祝你有个美好的一天。

解决方法

我解决了这个问题,就是我finish()在广告显示之前打电话,为了解决这个问题,我将整个部分移动到了onRewarded()

如果其他人遇到这个问题,这个ia会抬头。

问题

I know the videos are loading because the toast message pops up saying it did, and the video displayed once the very first time i tested it yesterday, but its been a whole day now and they still won't show. No error, no crashes.

package com.example.matthew.myapplication;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.reward.RewardItem;
import com.google.android.gms.ads.reward.RewardedVideoAd;
import com.google.android.gms.ads.reward.RewardedVideoAdListener;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;



public class createGame extends Activity implements RewardedVideoAdListener {
    private Button make;
    private EditText iDd, nam;
    DatabaseReference myRef;
    DataSnapshot datas;
    boolean canGo = false;
    private RewardedVideoAd mAd;

    protected void onCreate(Bundle savedInstanceState) {

        mAd = MobileAds.getRewardedVideoAdInstance(this);
        mAd.setRewardedVideoAdListener(this);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.creategame);
        Intent task = getIntent();
        addListenerOnButton();
        myRef = FirebaseDatabase.getInstance().getReference();
        ValueEventListener postListener = new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                datas = dataSnapshot;
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        };
        myRef.addValueEventListener(postListener);
        loadRewardedVideoAd();
    }


    public void addListenerOnButton() {


        make = (Button) findViewById(R.id.done);
        nam = (EditText) findViewById(R.id.nam);
        iDd = (EditText) findViewById(R.id.makeId);


        make.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                if (mAd.isLoaded()) {
                    mAd.show();
                    Log.d("Here is a test spot", "showing!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); //this log messagr also comes up confirming the ad is loaded bht it doesn't show for whatever reason
                }

                    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
                    String iDD = user.getUid();
                    String gameId = iDd.getText().toString();
                    myRef.child(gameId).child("DM").setValue(iDD);
                    int check2 = 0;
                    boolean done2 = false;
                    while (done2 == false) {
                        String sCheck2 = Integer.toString(check2);
                        if (datas.child(iDD).child("Game List").hasChild(sCheck2)) {
                            check2 = check2 + 1;
                            Log.d("Here is a test spot", "Made it here. 3");
                        } else {
                            myRef.child(iDD).child("Game List").child(sCheck2).setValue(gameId);
                            done2 = true;
                            Log.d("Here is a test spot", "Made it here. 4");
                        }
                    }
                    myRef.child(gameId).child("GAMEID").setValue(gameId);
                    myRef.child(gameId).child("GAME NAME").setValue(nam.getText().toString());
                    myRef.child(gameId).child("Events").child("0").setValue("Game Created.");
                    myRef.child(gameId).child("MRE").setValue("Game Created.");
                    myRef.child(gameId).child("Current Player").setValue("None");
                    myRef.child(gameId).child("pResponse").setValue("No Response Yet");
                    Intent TaskIntent = new Intent(getApplicationContext(), MainScreen.class);
                    startActivity(TaskIntent);
                    finish();

            }
        });

    }

    private void loadRewardedVideoAd() {
        mAd.loadAd("ca-app-pub-3940256099942544/5224354917", new AdRequest.Builder().build());
    }

    @Override
    public void onRewarded(RewardItem reward) {
        canGo = true;
    }

    // The following listener methods are optional.
    @Override
    public void onRewardedVideoAdLeftApplication() {
        Toast.makeText(this, "onRewardedVideoAdLeftApplication",
                Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onRewardedVideoAdClosed() {
        Toast.makeText(this, "onRewardedVideoAdClosed", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onRewardedVideoAdFailedToLoad(int errorCode) {
        Toast.makeText(this, "onRewardedVideoAdFailedToLoad", Toast.LENGTH_LONG).show();
        Log.d("ERROR", Integer.toString(errorCode));
    }

    @Override
    public void onRewardedVideoAdLoaded() {
        Toast.makeText(this, "onRewardedVideoAdLoaded", Toast.LENGTH_LONG).show();
    }

    @Override
    public void onRewardedVideoAdOpened() {
        Toast.makeText(this, "onRewardedVideoAdOpened", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onRewardedVideoStarted() {
        Toast.makeText(this, "onRewardedVideoStarted", Toast.LENGTH_SHORT).show();
    }
}

There is my code, and it is all right, but I still don't get why the ads wont show. Any help is much appreciated, have a good day.

解决方法

I solved the problem, it was that I'm calling finish() before the ad displays, and to solve this i moved that entire portion to the onRewarded()

This i a heads up if anyone else encounters this issue.

相似信息