我知道这些视频正在加载,因为吐出的信息会弹出来,并且昨天我第一次测试时显示了视频,但现在已经整整一天,但它们仍然无法显示。没有错误,没有崩溃。
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();
}
}
有我的代码,没关系,但我仍然不明白为什么广告不会显示。非常感谢任何帮助,祝你有个美好的一天。
答案 0 :(得分:0)
我解决了问题,就是我在广告显示之前调用了finish()
,为了解决这个问题,我将整个部分移到onRewarded()
如果其他人遇到这个问题,我就会抬头。