2

我已经在我的应用程序中实现了 MobFox。

我有两个问题。

  1. 即使在测试模式下,起初广告无法加载(bannerLoadFailed)然后我看到它(bannerLoadSucceeded)。这是由 onResume() 方法引起的。没有它,加载就不会失败。为什么?

  2. 它不显示任何广告。在测试模式下,它会在模拟器中和从市场下载的测试广告中显示,但在实时模式下,该noAdFound()方法处于活动状态,在 toast 中显示“未找到 MobFox 广告”。根据文档

noAdFound 表示当前没有可用于广告请求的广告

我来自匈牙利,但朋友在 MobFox 总部所在的奥地利下载了该应用程序,所以我怀疑奥地利没有广告请求...

MobFox 仪表板显示 3 次展示,我不知道它们是否来自测试广告。如果它们来自真实广告,则问题 2 可以忽略,但我仍然不知道为什么我的朋友看不到任何广告。

请您看一下代码以查看可能导致问题的原因(是否存在)?

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
            MobFoxlayout = (RelativeLayout)findViewById(R.id.mobfoxContent);
            mobfoxView = new MobFoxView(Main.this, "211bcbf66f79c0355e43e849aec76b6c", Mode.LIVE, true, true);
            mobfoxView.setBannerListener(new BannerListener() {

            @Override
            public void bannerLoadFailed(RequestException cause) {
                Toast.makeText(getApplicationContext(), "Mobfox ad failed ", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void noAdFound() {
                Toast.makeText(getApplicationContext(), "No MobFox ad Found", Toast.LENGTH_SHORT).show();
            }
            @Override
            public void bannerLoadSucceeded() {
                Toast.makeText(getApplicationContext(), "MobFox Ad loaded successfully", Toast.LENGTH_SHORT).show();    
            }

            @Override
            public void adClicked() {
                Toast.makeText(getApplicationContext(), "MobFox Ad clicked", Toast.LENGTH_SHORT).show();
            }
            });
            MobFoxlayout.addView(mobfoxView);
    }
    @Override
    protected void onResume() {  //ad fails to load
        super.onResume();
        mobfoxView.resume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        mobfoxView.pause();
    }



@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mobfoxView.pause();
mobfoxView.resume();
}
4

1 回答 1

1

我不知道出了什么问题,但它有效。我正在发布整个代码以供其他人帮助。这段代码最重要的部分是,当 MobFox 广告失败时,我设法展示了 admob 广告!

重要的是,如果您将 MobFox 广告切换到测试模式,您将在模拟器中看到测试广告。在我的手机上,我没有看到任何实时或测试广告,但我在 MobFox 仪表板上看到了很多展示。有时我也看不到任何 admob 广告。在我的手机上,我曾经见过他们,在我兄弟的手机上,我们从未见过他们。但考虑到我从他们那里赚钱,他们就在那里。

public class MainActivity extends Activity {

//MOBFOX----------------------------
private RelativeLayout rlayout;
private MobFoxView mobfoxView;

//ADMOB-----------------------------
private AdView adView;

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main2);
final Handler updateHandler = new Handler();
        rlayout = (RelativeLayout) findViewById(R.id.mobfoxContent);
        mobfoxView = new MobFoxView(MainActivity.this, "37a12617ccdc6bd4bafdded4e8441bca", Mode.LIVE, false, false);
        mobfoxView.setBannerListener(new BannerListener() {
        @Override
        public void bannerLoadFailed(RequestException cause) {
            //Toast.makeText(getApplicationContext(), "MobFox failed", Toast.LENGTH_LONG).show();
              adView = new AdView(MainActivity.this, AdSize.BANNER, MY_AD_UNIT_ID);
              LinearLayout layout = (LinearLayout)findViewById(R.id.admobContent);
              layout.addView(adView);
              adView.loadAd(new AdRequest());

        }
        @Override
        public void noAdFound() {
            //Toast.makeText(getApplicationContext(), "MobFox noAd", Toast.LENGTH_LONG).show();
              adView = new AdView(MainActivity.this, AdSize.BANNER, MY_AD_UNIT_ID);
              LinearLayout layout = (LinearLayout)findViewById(R.id.admobContent);
              layout.addView(adView);
              adView.loadAd(new AdRequest());

        }
        @Override
        public void adClicked() {
            //Toast.makeText(getApplicationContext(), "MobFox clicked", Toast.LENGTH_LONG).show();
            // TODO Auto-generated method stub

        }
        @Override
        public void bannerLoadSucceeded() {
            //Toast.makeText(getApplicationContext(), "MobFox success", Toast.LENGTH_LONG).show();
            // TODO Auto-generated method stub

        }
        });

        mobfoxView.setVisibility(View.VISIBLE);
        mobfoxView.setOnClickListener(new android.view.View.OnClickListener(){

            @Override
            public void onClick(View v) {
                updateHandler.post(new Runnable() {
                    public void run() {
                        //Toast.makeText(getApplicationContext(), "MobFox clicked2", Toast.LENGTH_LONG).show();
                    }
                });

            }});


        rlayout.addView(mobfoxView);

}

    @Override
    protected void onDestroy() {

        if (adView != null) {
                adView.destroy();
        }
        super.onDestroy();
        //mManager.release();
    }
    @Override
    protected void onPause() {
        super.onPause();
        mobfoxView.pause();
    }

    @Override
    protected void onResume() {
        super.onResume();
        mobfoxView.resume();
    }
}

xml:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/bg_selector"
    android:orientation="vertical" >

<!-- objects -->

     <LinearLayout 
        android:id="@+id/admobContent"
        android:layout_alignParentBottom="true"
        android:layout_width="fill_parent"
        android:layout_height="50dp">
    </LinearLayout>

   <RelativeLayout 
        android:id="@+id/mobfoxContent"
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true" />

</RelativeLayout>

并且不要忘记这些到所有布局文件夹!

于 2012-10-27T14:41:59.817 回答