如何处理 android 中的 AdMob onAdFailedToLoad?
How can I handle the AdMob onAdFailedToLoad in android?
Hello Dev's can anyone know how to handle the onAdFailedToLoad code, I have an app which has timer functionality there is 3 type of timer 1. Short break 2. Long break and 3. Skip break, I set the interstitial ad on these three buttons, let spouse if user have internet after that user clicks on any of these 3 buttons after clicking the button the loading popup will show and in the background an ad is loaded the ad will be showing, but.... problem is if the user has no internet then popup is loading infinitely, how to handle that. Here is the code.
private void init_Interstitial_ads() {
InterstitialAd.load(this, "ca-app-pub-9852745157515787/5999732991", adRequest,
new InterstitialAdLoadCallback() {
@Override
public void onAdLoaded(@NonNull InterstitialAd interstitialAd) {
// The mInterstitialAd reference will be null until
// an ad is loaded.
mInterstitialAd = interstitialAd;
mInterstitialAd.show(HomeActivity.this);
loadingDialog.dismiss_loadingDialog();
// Toast.makeText(HomeActivity.this, "Ad Loaded", Toast.LENGTH_SHORT).show();
}
@Override
public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
// Handle the error
mInterstitialAd = null;
// Toast.makeText(HomeActivity.this, "Ad Not Loaded", Toast.LENGTH_SHORT).show();
}
});
}
void userAdPromt() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
init_Interstitial_ads();
}
}, 2000);
}
start_short_break.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
loadingDialog.start_loadingDialog();
userAdPromt();
String currentButtonText = start_short_break.getText().toString();
start_Break_From_Alert_Popup(currentButtonText);
//mInterstitialAd.show(HomeActivity.this);
}
});
start_long_break.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
loadingDialog.start_loadingDialog();
userAdPromt();
String currentButtonText = start_long_break.getText().toString();
start_Break_From_Alert_Popup(currentButtonText);
//mInterstitialAd.show(HomeActivity.this);
}
});
skipBreakSmallButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
loadingDialog.start_loadingDialog();
userAdPromt();
sessionCancel(HomeActivity.this, preferences);
//mInterstitialAd.show(HomeActivity.this);
}
});
尝试关闭 AdFailedToLoad
函数中的 loadingDialog
。
Hello Dev's can anyone know how to handle the onAdFailedToLoad code, I have an app which has timer functionality there is 3 type of timer 1. Short break 2. Long break and 3. Skip break, I set the interstitial ad on these three buttons, let spouse if user have internet after that user clicks on any of these 3 buttons after clicking the button the loading popup will show and in the background an ad is loaded the ad will be showing, but.... problem is if the user has no internet then popup is loading infinitely, how to handle that. Here is the code.
private void init_Interstitial_ads() {
InterstitialAd.load(this, "ca-app-pub-9852745157515787/5999732991", adRequest,
new InterstitialAdLoadCallback() {
@Override
public void onAdLoaded(@NonNull InterstitialAd interstitialAd) {
// The mInterstitialAd reference will be null until
// an ad is loaded.
mInterstitialAd = interstitialAd;
mInterstitialAd.show(HomeActivity.this);
loadingDialog.dismiss_loadingDialog();
// Toast.makeText(HomeActivity.this, "Ad Loaded", Toast.LENGTH_SHORT).show();
}
@Override
public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
// Handle the error
mInterstitialAd = null;
// Toast.makeText(HomeActivity.this, "Ad Not Loaded", Toast.LENGTH_SHORT).show();
}
});
}
void userAdPromt() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
init_Interstitial_ads();
}
}, 2000);
}
start_short_break.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
loadingDialog.start_loadingDialog();
userAdPromt();
String currentButtonText = start_short_break.getText().toString();
start_Break_From_Alert_Popup(currentButtonText);
//mInterstitialAd.show(HomeActivity.this);
}
});
start_long_break.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
loadingDialog.start_loadingDialog();
userAdPromt();
String currentButtonText = start_long_break.getText().toString();
start_Break_From_Alert_Popup(currentButtonText);
//mInterstitialAd.show(HomeActivity.this);
}
});
skipBreakSmallButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
loadingDialog.start_loadingDialog();
userAdPromt();
sessionCancel(HomeActivity.this, preferences);
//mInterstitialAd.show(HomeActivity.this);
}
});
尝试关闭 AdFailedToLoad
函数中的 loadingDialog
。