Facebook Audience网络非页内广告崩溃

时间:2017-12-28 11:06:07

标签: android facebook interstitial

if (myApp.finterstitialAd3 == null) {
   myApp.finterstitialAd3 = new com.facebook.ads.InterstitialAd(this, getResources().getString(R.string.finterstitial3));
}
if (!myApp.finterstitialAd3.isAdLoaded()) {
    myApp.finterstitialAd3.loadAd();
}
  

java.lang.RuntimeException:无法启动活动ComponentInfo {}:java.lang.IllegalStateException:在显示时无法加载InterstitialAd。确保您的适配器调用adapterListener.onInterstitialDismissed()。                                                                                               在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2678)                                                                                               在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2743)                                                                                               在android.app.ActivityThread.-wrap12(ActivityThread.java)                                                                                               在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1490)                                                                                               在android.os.Handler.dispatchMessage(Handler.java:102)                                                                                               在android.os.Looper.loop(Looper.java:154)                                                                                               在android.app.ActivityThread.main(ActivityThread.java:6165)                                                                                               at java.lang.reflect.Method.invoke(Native Method)                                                                                               在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:888)                                                                                               在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)                                                                                            引起:java.lang.IllegalStateException:在显示时无法加载InterstitialAd。确保您的适配器调用adapterListener.onInterstitialDismissed()。                                                                                               在com.facebook.ads.InterstitialAd.a(未知来源)                                                                                               at com.facebook.ads.InterstitialAd.loadAd(Unknown Source)                                                                                               at com.facebook.ads.InterstitialAd.loadAd(Unknown Source)                                                                                               at“------------------------”。loadInterstitial(VideoDetail.java:121)                                                                                               在“-------”。onCreate(VideoDetail.java:225)                                                                                               在android.app.Activity.performCreate(Activity.java:6687)                                                                                               在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1140)                                                                                               在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2631)                                                                                               在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2743)                                                                                               在android.app.ActivityThread.-wrap12(ActivityThread.java)                                                                                               在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1490)                                                                                               在android.os.Handler.dispatchMessage(Handler.java:102)                                                                                               在android.os.Looper.loop(Looper.java:154)                                                                                               在android.app.ActivityThread.main(ActivityThread.java:6165)                                                                                               at java.lang.reflect.Method.invoke(Native Method)                                                                                               在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:888)                                                                                               在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)

2 个答案:

答案 0 :(得分:0)

我在com.facebook.ads.InterstitialAd对象中遇到此问题。我试图在已经显示的插页式广告上调用loadAd()。 对我来说,解决方案是在加载新广告之前销毁旧实例并创建一个新实例:

if(interstitialAd != null)
    interstitialAd.destroy();
interstitialAd = new com.facebook.ads.InterstitialAd(context, id);

Facebook也有一种测试广告的新方法,因此为了方便您进行测试,您可以添加" IMG_16_9_APP_INSTALL#"在广告ID之前(这将确保您的广告请求始终填写进行测试),然后将其删除以用于发布版本。

答案 1 :(得分:0)

Android应用程序上的Facebook非页内广告

Build.Gradle:

implementation 'com.facebook.android:audience-network-sdk:5.+'

MyAplication.java:

AudienceNetworkAds.initialize(this);

Manifest.xml:

<activity
     android:name="com.facebook.ads.AudienceNetworkActivity"
     android:configChanges="keyboardHidden|orientation|screenSize" />

权限:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

MainActivity:

public class MainActivity extends AppCompatActivity {


    private InterstitialAd facebookInterstitialAds;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        showFacebookInterstitial();
    }

    private void showFacebookInterstitial() {

        facebookInterstitialAds = new InterstitialAd(this, "Interstitial_Ad_ID");
        facebookInterstitialAds.setAdListener(new InterstitialAdListener() {
            @Override
            public void onInterstitialDisplayed(Ad ad) {
            }
            @Override
            public void onInterstitialDismissed(Ad ad) {
                finish();
            }
            @Override
            public void onError(Ad ad, AdError adError) {
            }
            @Override
            public void onAdLoaded(Ad ad) {
            }
            @Override
            public void onAdClicked(Ad ad) {
            }
            @Override
            public void onLoggingImpression(Ad ad) {
            }
        });
        facebookInterstitialAds.loadAd();
    }


    public void showAds(View view){

        if (facebookInterstitialAds.isAdLoaded())
            facebookInterstitialAds.show();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (facebookInterstitialAds != null)
            facebookInterstitialAds.destroy();
    }
}