Facebook广告没有显示android

时间:2015-12-09 06:51:14

标签: android facebook

我正在开发和需要显示Facebook横幅广告的Android应用程序,因为我已经成功生成了Placement id并实现了Facebook开发者网站建议的代码。但问题是广告没有显示。在调试时我发现这个No Fill Error。我在谷歌搜索过这个错误但无法解决它。任何帮助将不胜感激。这是我的代码:

AdView adView;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Instantiate an AdView view
    adView = new AdView(this, PLACEMENT_ID, AdSize.BANNER_HEIGHT_50);

    // Find the main layout of your activity
    LinearLayout layout = (LinearLayout)findViewById(R.id.activityLayout);

    // Add the ad view to your activity layout
    layout.addView(adView);

    adView.setAdListener(new AdListener() {

        @Override
        public void onError(Ad ad, AdError error) {
            // Ad failed to load. 
            // Add code to hide the ad's view
        }

        @Override
        public void onAdLoaded(Ad ad) {
            // Ad was loaded
            // Add code to show the ad's view
        }

        @Override
        public void onAdClicked(Ad ad) {
            // Use this function to detect when an ad was clicked.
        }

    });


    // Request to load an ad    
    adView.loadAd();
}

2 个答案:

答案 0 :(得分:0)

经过大量搜索,我找到了广告没有显示的解决方案,实际上我的应用程序不是实时的(在谷歌游戏商店中)所以尝试使用Facebook帐户登录您的应用程序,通过该帐户生成放置ID。它会起作用。

答案 1 :(得分:0)

您需要声明Facebook Adview不是Google Adview。

在Gradle中:

  implementation 'com.facebook.android:audience-network-sdk:4.99.1'

活动中:

com.facebook.ads.AdView adView;
adView = new com.facebook.ads.AdView(this,"PLACEMENTID",com.facebook.ads.AdSize.BANNER_HEIGHT_50);
((LinearLayout) adContainer).addView(adView);
adView.loadAd();