MoPub "onInterstitialFailed" 离线时 adListener 不工作
MoPub "onInterstitialFailed" adListener not work when offline
我正在显示 MoPub Interstitial ad
到 activities
。
When my device online/connect with internet. Then adListener
work
properly.This not work when device OFFLINE.
情况:如果ad
not loaded
或者failed
那么我想用Intent
那里去下一步activity
。 但是这个MoPubAdListener
在我离线时不起作用。
onCreate
方法
中的插页式 mInterstitial.load()
当用户按下后退按钮时,会调用插页式广告
@Override
public void onBackPressed() {
try {
customProgressDialogForAd.show(getSupportFragmentManager(),"before interstitial");
funInterstitialLoadShow();
} catch (Exception e){
QuestionActivity.super.onBackPressed();
}
//super.onBackPressed();
}
插播功能
private void funInterstitialLoadShow(){
mInterstitial.setInterstitialAdListener(new MoPubInterstitial.InterstitialAdListener() {
@Override
public void onInterstitialLoaded(MoPubInterstitial moPubInterstitial) {
Toast.makeText(QuestionActivity.this, "adloaded", Toast.LENGTH_SHORT).show();
mInterstitial.show();
customProgressDialogForAd.dismiss();
}
@Override
public void onInterstitialFailed(MoPubInterstitial moPubInterstitial, MoPubErrorCode moPubErrorCode) {
customProgressDialogForAd.dismiss();
QuestionActivity.super.onBackPressed();
// PROBLEM HERE: THIS fun now work when Device is OFFLINE(NO INTERNET);
}
@Override
public void onInterstitialShown(MoPubInterstitial moPubInterstitial) {
}
@Override
public void onInterstitialClicked(MoPubInterstitial moPubInterstitial) {
}
@Override
public void onInterstitialDismissed(MoPubInterstitial moPubInterstitial) {
customProgressDialogForAd.dismiss();
QuestionActivity.super.onBackPressed();
}
});
}
问题:onInterstitialFailed
当设备未连接到互联网时无法工作。 [另一方面,如果设备中的互联网处于打开状态,则 sdk 可以正常工作,例如,如果我们关闭广告,则 onInterstitialDismissed
可以正常工作]
任何解决方案:请
有两个way/method/type,调用MoPub的AdListener
。
第一种方式:直接调用adListener
mInterstitial.setInterstitialAdListener(new MoPubInterstitial.InterstitialAdListener() { .... }
第二种方式: 通过 implements
在我们的 Activity class
[ 中调用 MoPub AdListener
=23=]
public class QuestionActivity extends AppCompatActivity implements MoPubInterstitial.InterstitialAdListener { ... }
解决方案:
您没有将 mInterstitial.load()
与 adListener
一起使用。如果不添加带有 AdListener
的这一行代码,Adlistener
的功能将不起作用 因为这一行是 adListener
.
的一部分
// ====this function (with moPub ad listener)== called when use click back button
public void funInterstitialAdListener(){
mInterstitial.setInterstitialAdListener(new MoPubInterstitial.InterstitialAdListener() {
@Override
public void onInterstitialLoaded(MoPubInterstitial moPubInterstitial) {
Log.d(TAG, "onInterstitialLoaded: funAd loaded");
customProgressDialogForAd.dismiss();
mInterstitial.show();
}
@Override
public void onInterstitialFailed(MoPubInterstitial moPubInterstitial, MoPubErrorCode moPubErrorCode) {
customProgressDialogForAd.dismiss();
QuestionActivity.super.onBackPressed();
Log.d(TAG, "onInterstitialFailed: ad failed to load");
}
@Override
public void onInterstitialShown(MoPubInterstitial moPubInterstitial) {
}
@Override
public void onInterstitialClicked(MoPubInterstitial moPubInterstitial) {
}
@Override
public void onInterstitialDismissed(MoPubInterstitial moPubInterstitial) {
Log.d(TAG, "onInterstitialDismissed: Done");
QuestionActivity.super.onBackPressed();
}
});
// If we not use this mInterstitial.load() code, then function of AdListener not work.
mInterstitial.load();
// Must use this upper line with adListener. This line is part of AdListener.
}
快乐编码:)
我正在显示 MoPub Interstitial ad
到 activities
。
When my device online/connect with internet. Then
adListener
work properly.This not work when device OFFLINE.
情况:如果ad
not loaded
或者failed
那么我想用Intent
那里去下一步activity
。 但是这个MoPubAdListener
在我离线时不起作用。
onCreate
方法
mInterstitial.load()
当用户按下后退按钮时,会调用插页式广告
@Override
public void onBackPressed() {
try {
customProgressDialogForAd.show(getSupportFragmentManager(),"before interstitial");
funInterstitialLoadShow();
} catch (Exception e){
QuestionActivity.super.onBackPressed();
}
//super.onBackPressed();
}
插播功能
private void funInterstitialLoadShow(){
mInterstitial.setInterstitialAdListener(new MoPubInterstitial.InterstitialAdListener() {
@Override
public void onInterstitialLoaded(MoPubInterstitial moPubInterstitial) {
Toast.makeText(QuestionActivity.this, "adloaded", Toast.LENGTH_SHORT).show();
mInterstitial.show();
customProgressDialogForAd.dismiss();
}
@Override
public void onInterstitialFailed(MoPubInterstitial moPubInterstitial, MoPubErrorCode moPubErrorCode) {
customProgressDialogForAd.dismiss();
QuestionActivity.super.onBackPressed();
// PROBLEM HERE: THIS fun now work when Device is OFFLINE(NO INTERNET);
}
@Override
public void onInterstitialShown(MoPubInterstitial moPubInterstitial) {
}
@Override
public void onInterstitialClicked(MoPubInterstitial moPubInterstitial) {
}
@Override
public void onInterstitialDismissed(MoPubInterstitial moPubInterstitial) {
customProgressDialogForAd.dismiss();
QuestionActivity.super.onBackPressed();
}
});
}
问题:onInterstitialFailed
当设备未连接到互联网时无法工作。 [另一方面,如果设备中的互联网处于打开状态,则 sdk 可以正常工作,例如,如果我们关闭广告,则 onInterstitialDismissed
可以正常工作]
任何解决方案:请
有两个way/method/type,调用MoPub的AdListener
。
第一种方式:直接调用adListener
mInterstitial.setInterstitialAdListener(new MoPubInterstitial.InterstitialAdListener() { .... }
第二种方式: 通过 implements
在我们的 Activity class
[ 中调用 MoPub AdListener
=23=]
public class QuestionActivity extends AppCompatActivity implements MoPubInterstitial.InterstitialAdListener { ... }
解决方案:
您没有将 mInterstitial.load()
与 adListener
一起使用。如果不添加带有 AdListener
的这一行代码,Adlistener
的功能将不起作用 因为这一行是 adListener
.
// ====this function (with moPub ad listener)== called when use click back button
public void funInterstitialAdListener(){
mInterstitial.setInterstitialAdListener(new MoPubInterstitial.InterstitialAdListener() {
@Override
public void onInterstitialLoaded(MoPubInterstitial moPubInterstitial) {
Log.d(TAG, "onInterstitialLoaded: funAd loaded");
customProgressDialogForAd.dismiss();
mInterstitial.show();
}
@Override
public void onInterstitialFailed(MoPubInterstitial moPubInterstitial, MoPubErrorCode moPubErrorCode) {
customProgressDialogForAd.dismiss();
QuestionActivity.super.onBackPressed();
Log.d(TAG, "onInterstitialFailed: ad failed to load");
}
@Override
public void onInterstitialShown(MoPubInterstitial moPubInterstitial) {
}
@Override
public void onInterstitialClicked(MoPubInterstitial moPubInterstitial) {
}
@Override
public void onInterstitialDismissed(MoPubInterstitial moPubInterstitial) {
Log.d(TAG, "onInterstitialDismissed: Done");
QuestionActivity.super.onBackPressed();
}
});
// If we not use this mInterstitial.load() code, then function of AdListener not work.
mInterstitial.load();
// Must use this upper line with adListener. This line is part of AdListener.
}
快乐编码:)