I have implemented MobFox in my application.
I have two problems.
Even in test mode, at first the ad fails to load (bannerLoadFailed) then I see it (bannerLoadSucceeded). This is caused by the onResume() method. Without that, there is no fail in loading. Why?
It does not show any ads. In test mode it shows the test ad, both in the emulator and by downloaded from the market, but in live mode the noAdFound()
method is active, saying "No MobFox ad found" in the toast.
According to the documentation
noAdFound means that there is currently no ad available for the ad request
I am from Hungary, but a friend downloaded the app in Austria, where MobFox headquarters is, so I doubt there are no ad requests in Austria...
The MobFox dashboard shows 3 impressions, I don't know if they are coming from the test ad. If they are coming from real ads, question 2 is ignorable, but still I don't know why my friend cannot see any ads.
Would you please take a look at the code to see what may cause the problem (is there is one)?
@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();
}
I don't know what was wrong but it works. I am posting the whole code for others to help. The great part in this code is that I managed to show admob ads when MobFox ads are failed!
It is important that if you switch the MobFox ads to Test mode you will see the test ad in the emulator. On my phone I haven't seen any live or test ads, but I see many impressions on my MobFox dashboard. Sometimes I don't see any admob ads either. On my phone I used to see them, on my brother's phone we have never seen them. But they are there considering I earn from them.
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>
And don't forget to these to all layout folders!