I use GPS to provide ads in my application, but there are blank box until ad is loaded and also when user doesn't have access to te Internet and it's look awful. This is i think changed behaviour in GPS SDK in migration from dedicated AdMob SDK (which is deprecated).
I tried out set listeners for onAdLoaded, which set visibility to
visible after load from gone i set after create, but there is a serious
problem. This is doesn't show a blank box on application start and show
ad after her load. However when there are not access to the Internet,
onAdLoaded don't fired anytime because of hidden Ad! Also return these
logs:
Ad is not visible. Not refreshing ad.
Scheduling ad refresh 60000 milliseconds from now.
In this situation, user never sees the ad... How can I prevent GPS Ads doing this?
There is my code placed in main activity:
adView = new AdView(this); adView.setAdListener(new AdListener() { @Override public void onAdLoaded() { adView.setVisibility(View.VISIBLE); super.onAdLoaded(); } }); adView.setVisibility(View.GONE); adView.setAdUnitId("xxx"); adView.setAdSize(AdSize.SMART_BANNER); layout = super.root; layout.addView(adView); adRequest = new AdRequest.Builder().build(); adView.loadAd(adRequest);
For more options, visit https://groups.google.com/d/optout.--
---
You received this message because you are subscribed to the Google Groups "Google AdMob Ads Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
adView = new AdView(this);
adView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
adView.setVisibility(View.VISIBLE);
//Toast.makeText(getContext(), "Nahráno", Toast.LENGTH_LONG).show();
}
public void onAdFailedToLoad(int errorCode) {
adView.setVisibility(View.GONE); // aby tam nebyl vidět černý čtverec, když se nepodaří načíst reklamu
//Toast.makeText(getContext(), "Blbě", Toast.LENGTH_LONG).show();
}
});
//adView.setVisibility(View.GONE);
adView.setAdUnitId("xxx");
adView.setAdSize(AdSize.SMART_BANNER);
// Lookup your LinearLayout assuming it's been given
// the attribute android:id="@+id/mainLayout".
layout = super.root;
// Add the adView to it.
layout.addView(adView);
// Initiate a generic request.
adRequest = new AdRequest.Builder().build();
// Load the adView with the ad request.
adView.loadAd(adRequest);
...
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:visibility="gone">
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="@string/ad_unit_id"/>
</FrameLayout>
mAdView = (AdView) findViewById(R.id.adView);
mAdView.setAdListener(new AdListener() {
/*
* (non-Javadoc)
* @see com.google.android.gms.ads.AdListener#onAdLoaded()
*/
@Override
public void onAdLoaded() {
FrameLayout adViewContainer = (FrameLayout) mAdView.getParent();
adViewContainer.setVisibility (View.VISIBLE);
adViewContainer.startAnimation(AnimationUtils.makeInChildBottomAnimation(mAdView.getContext()));
}
});
mAdView.loadAd(new AdRequest.Builder().build());
AdContainer = new FrameLayout(this);
AdContainer.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, Gravity.BOTTOM));
AdContainer.setVisibility(View.GONE);
layout = super.root;
layout.addView(AdContainer);
adView = new AdView(this);
adView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
AdContainer.setVisibility(View.VISIBLE);
}
});
//adView.setVisibility(View.GONE);
adView.setAdUnitId("xxx");
adView.setAdSize(AdSize.SMART_BANNER);
// Lookup your LinearLayout assuming it's been given
// the attribute android:id="@+id/mainLayout".
// Add the adView to it.
AdContainer.addView(adView);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_banner_code_ad_listener);
// AdView helper...
mAdViewHelper = new AdViewHelper(this, (RelativeLayout) findViewById(R.id.mainLayout));
mAdViewHelper.refresh();
}
@Override
protected void onPause() {
mAdViewHelper.pause();
super.onPause();
}
@Override
protected void onResume() {
super.onResume();
mAdViewHelper.resume();
}
@Override
protected void onDestroy() {
mAdViewHelper.destroy();
super.onDestroy();
}
public class AdViewHelper {
/**
* Constants
*/
private final static String TAG = "AdViewHelper";
/**
* Members
*/
private Context mContext;
private Handler mHandler;
private ViewGroup mAdViewContainer;
private AdView mAdView;
private AdListener mAdViewListener;
/**
* Members
*/
public AdViewHelper(Context pContext, ViewGroup pViewGroup) {
// Init
mContext = pContext;
mHandler = new Handler();
// AdViewContainer...
mAdViewContainer = new FrameLayout(mContext);
mAdViewContainer.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, Gravity.BOTTOM));
mAdViewContainer.setVisibility(View.GONE);
pViewGroup.addView(mAdViewContainer);
// AdViewListener...
mAdViewListener = new AdListener() {
/*
* (non-Javadoc)
* @see com.google.android.gms.ads.AdListener#onAdLoaded()
*/
@Override
public void onAdLoaded() {
// Show ad...
mAdViewContainer.setVisibility(View.VISIBLE);
}
/*
* (non-Javadoc)
* @see com.google.android.gms.ads.AdListener#onAdFailedToLoad(int)
*/
@Override
public void onAdFailedToLoad(int errorCode) {
// Fail...
Log.e(TAG, String.format("onAdFailedToLoad(%s)", errorCode));
// Refresh it ourselves...
mHandler.removeCallbacks(null);
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
refresh();
}
}, 60000);
}
};
}
/**
* Refresh ad.
*/
public final void refresh() {
// Destroy old instance...
destroy();
// Create new instance...
mAdView = new AdView(mContext);
mAdView.setAdUnitId(mContext.getResources().getString(R.string.ad_unit_id));
mAdView.setAdSize(AdSize.BANNER);
mAdView.setAdListener(mAdViewListener);
// Add to container...
mAdViewContainer.addView(mAdView);
// Request new ad...
mAdView.loadAd(new AdRequest.Builder().build());
}
/**
* Pause ad.
*/
public final void pause() {
mAdView.pause();
}
/**
* Resume ad.
*/
public final void resume() {
mAdView.resume();
}
/**
* Destroy ad.
*/
public void destroy() {
mHandler.removeCallbacks(null);
if (mAdView != null) {
mAdView.destroy();
}
mAdViewContainer.removeAllViews();
}
handler.removeCallbacksAndMessages(null) instead of handler.removeCallbacks(null) to correct remove all handlers in this case.
Brother use adview in xml and set its visibility to gone and then access it in java file through findviewbyid method and then set the listener it works for me
adView = (Adview)findviewById(R.id.adview); adView.setAdListener(new AdListener() { @Override public void onAdLoaded() { adView.setVisibility(View.VISIBLE); super.onAdLoaded(); } }); adView.setVisibility(View.GONE); adView.setAdUnitId("xxx"); adView.setAdSize(AdSize.SMART_BANNER); layout = super.root; layout.addView(adView); adRequest = new AdRequest.Builder().build(); adView.loadAd(adRequest);
--
---
You received this message because you are subscribed to a topic in the Google Groups "Google AdMob Ads Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-admob-ads-sdk/X4TqlA1sD6o/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-admob-ads...@googlegroups.com.
To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To unsubscribe from this group and all its topics, send an email to google-admob-ads...@googlegroups.com.
It's even worse when they have the on-screen keyboard showing, and there is a large gap above the keyboard.
It kind of creates a poor user experience when the user sees a large empty gap near the bottom of the screen. This can be visible for a long time, if there is no Internet connection.
It's even worse when they have the on-screen keyboard showing, and there is a large gap above the keyboard.
private boolean mAdInViewHierarchy = false;
...
mAdView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
super.onAdLoaded();
if (!mAdInViewHierarchy) {
RelativeLayout mainLayout = (RelativeLayout) findViewById(R.id.mainLayout);
mainLayout.addView(mAdView);
mAdInViewHierarchy = true;
}
}
});
I use GPS to provide ads in my application, but there are blank box until ad is loaded and also when user doesn't have access to te Internet and it's look awful. This is i think changed behaviour in GPS SDK in migration from dedicated AdMob SDK (which is deprecated).
I tried out set listeners for onAdLoaded, which set visibility to visible after load from gone i set after create, but there is a serious problem. This is doesn't show a blank box on application start and show ad after her load. However when there are not access to the Internet, onAdLoaded don't fired anytime because of hidden Ad! Also return these logs:
Ad is not visible. Not refreshing ad.
Scheduling ad refresh 60000 milliseconds from now.In this situation, user never sees the ad... How can I prevent GPS Ads doing this?
There is my code placed in main activity:
adView = new AdView(this); adView.setAdListener(new AdListener() { @Override public void onAdLoaded() { adView.setVisibility(View.VISIBLE); super.onAdLoaded(); } }); adView.setVisibility(View.GONE); adView.setAdUnitId("xxx"); adView.setAdSize(AdSize.SMART_BANNER); layout = super.root; layout.addView(adView); adRequest = new AdRequest.Builder().build(); adView.loadAd(adRequest);