Ad shows only if WI-FI was enabled before app start (it won't appear if wi-fi was enabled during app session). How to load Admob ad whenever it's possible? I believe, it's got something to do with AdListener. My current code:
adView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
adView.setVisibility(View.VISIBLE);
super.onAdLoaded();
}
public void onAdFailedToLoad(int errorCode) {
adView.setVisibility(View.GONE);
}
});
You need a BroadCastReceiver to know when the network status has changed so you can load your adds.
Then we have the AddListener class
And from the MainUI class we do this:
Also remember to register your BroadcastReceiver in your Manifest
And ask for these permissions:
If your question is to know, shall I load the ad or not based on the conditions required for the ad is satisfied like internet and
GooglePlayServices
, then you can use the method below:The method shouldLoadAd checks if internet and Googleplayservices is available then load ad else dont load ad, if it returns false you can hide the adView.