我遇到了没有显示的非页内广告的问题。 这是我要展示广告的活动。
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);
}
}
我已经阅读了有关Admob中的插页式广告的所有内容。但是,没有任何作用。横幅可能是问题吗?
答案 0 :(得分:0)
将interstitialAd = new InterstitialAd(this);
更改为
interstitialAd = new InterstitialAd(getContext());
并检查 adUnitId 是否正确。
否则一切似乎都很好。并且,不,插页式广告不会受到任何形式的横幅的影响,因为两者是完全不同的实体并且彼此独立。