Initialization functionality unavailable for this session, in google Ads - android

I'm getting this error of google Ads, suddently. I can't find anything here with this error.
Notice that ads are displaying correctly
Google Mobile Ads SDK initialization functionality unavailable for this session. Ad requests can be made at any time.

Have you tried restarting your test device? It worked for me. Also if you have other apps with admob try uninstalling them since numerous calls will be made leading to the problem you are experiencing.

In my case, I solved this error by adding the following lines to my onCreate method:
MobileAds.initialize(this, new OnInitializationCompleteListener() {
#Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
}
});
mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);

Related

Should we first call MobileAds.setRequestConfiguration or MobileAds.initialize?

There isn't much documentation on this. I was wondering, should we first call
RequestConfiguration conf= new RequestConfiguration.Builder()
.setMaxAdContentRating(
MAX_AD_CONTENT_RATING_T)
.build();
MobileAds.setRequestConfiguration(conf);
MobileAds.initialize(context, APP_ID);
Or
MobileAds.initialize(context, APP_ID);
RequestConfiguration conf= new RequestConfiguration.Builder()
.setMaxAdContentRating(
MAX_AD_CONTENT_RATING_T)
.build();
MobileAds.setRequestConfiguration(conf);
In https://developers.google.com/admob/android/quick-start
Although Google recommend calling MobileAds.initialize as early as possible
Before loading ads, have your app initialize the Mobile Ads SDK by
calling MobileAds.initialize() which initializes the SDK and calls
back a completion listener once initialization is complete (or after a
30-second timeout). This needs to be done only once, ideally at app
launch.
They also mention "request-specific flags" need to be set before MobileAds.initialize.
Warning: Ads may be preloaded by the Mobile Ads SDK or mediation
partner SDKs upon calling MobileAds.initialize(). If you need to
obtain consent from users in the European Economic Area (EEA), set any
request-specific flags (such as tagForChildDirectedTreatment or
tag_for_under_age_of_consent), or otherwise take action before loading
ads, ensure you do so before initializing the Mobile Ads SDK.
So, not super clear on which should be called first.
According to Google Developer support, the following is the right way to do
https://groups.google.com/forum/#!category-topic/google-admob-ads-sdk/android/17oVu0sABjs
RequestConfiguration conf= new RequestConfiguration.Builder()
.setMaxAdContentRating(
MAX_AD_CONTENT_RATING_T)
.build();
MobileAds.setRequestConfiguration(conf);
MobileAds.initialize(context, APP_ID);
It's done as such:
MobileAds.RequestConfiguration =
new RequestConfiguration
.Builder()
.SetTagForChildDirectedTreatment(RequestConfiguration.TagForChildDirectedTreatmentTrue)
.SetMaxAdContentRating(RequestConfiguration.MaxAdContentRatingG)
#if DEBUG
.SetTestDeviceIds(new[] { "..." })
#endif
.Build();
according to the official documentation
Before loading ads, have your app initialize the Mobile Ads SDK by calling MobileAds.initialize() which initializes the SDK and calls back a completion listener once initialization is complete (or after a 30-second timeout). This needs to be done only once, ideally at app launch.
So , you should initialize MobileAds first ,look at the example here form the official documentation :
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MobileAds.initialize(this, new OnInitializationCompleteListener() {
#Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
}
});
mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
}

My ad is not shown, ad failed to load : 3

After the last update of my application the admob ad banner no longer appears, the admob code has not changed, the problem persists for five days, can anyone help me?
When I use the test banner id the test ad is displayed, but when I return my banner id the ad disappears again.
MobileAds.initialize(this, new OnInitializationCompleteListener() {
#Override
public void onInitializationComplete(InitializationStatus
initializationStatus) {
}
});
adView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
I/Ads: This request is sent from a test device.
I/Ads: Ad failed to load : 3
D/FA: Logging event (FE): ad_query(_aq), Bundle[{firebase_event_origin(_o)=am, firebase_screen_class(_sc)=ClienteActivity, firebase_screen_id(_si)=5173973406731336718, ad_event_id(_aeid)=5173973406731336795}]
V/FA: Connecting to remote service
D/FA: Connected to remote service
V/FA: Processing queued up service tasks: 1
V/FA: Inactivity, disconnecting from the service
If you want to get ads on your app in test (debug) mode you need to include the below code to request test ads. It is good to test your app with test ads. Otherwise your admob account can be banned!
You need to obtain your device id for this. Run your app and check the console output. You will find this message in log.
I/Ads: Use
AdRequest.Builder.addTestDevice("YOUR_DEVICE_ID") to
get test ads on this device.
Update your code as below.
MobileAds.initialize(this, new OnInitializationCompleteListener() {
#Override
public void onInitializationComplete(InitializationStatus
initializationStatus) {
}
});
adView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().addTestDevice("YOUR_DEVICE_ID").build();
adView.loadAd(adRequest);
Read more about admob test ads here
To load ads using the AdMob demo ad-units you need to use the correct demo ad-unit ID for your ad-format (e.g. Banner, Interstitial, etc) as listed here: https://developers.google.com/admob/android/test-ads
Add your device ID as test/debug ID with this code:
List<String> testDeviceIds = Arrays.asList(YOUR_DEVICE_ID_FOR_TEST);
RequestConfiguration configuration = new RequestConfiguration.Builder().setTestDeviceIds(testDeviceIds).build();
MobileAds.setRequestConfiguration(configuration);
Also, if you are using app-ads.txt for your app, then you also have to include this line in your app-ads.txt file in order to load ads using the demo ad units (and wait for Google to crawl/update it):
google.com, pub-3940256099942544, DIRECT, f08c47fec0942fa0

Can I request new ad from onAdFailedToLoad?

During testing of my application, I noticed that I very frequently get ERROR_CODE_NO_FILL for Interstitial Ad. I think that the same situation with real ads might be one of the causes of low income from the application, so I want to increase the rate of showed ads. As the solution, I decided to make requests until I will get some app, so it might take from 5 to 50 requests until I will get out of onAdFailedToLoad. Is it a legitimate way to do this? Won't I get banned by AdMob with such way of getting more ads?
That's what I do in setAdListener in onCreate:
#Override
public void onAdFailedToLoad(int errorCode) {
requestNewInterstitial();
}
And requestNewInterstitial():
private void requestNewInterstitial() {
AdRequest adRequest = new AdRequest.Builder()
.build();
mInterstitialAd.loadAd(adRequest);
}
No, you won't get banned...
You can do this, but don't show the Ad as soon it is loaded, this will be a bombarding of Ads & user won't like that...

Admob live ads not showing in my application,while testing ads showing

Admob Live ads are not showing, while testing ads are showing. Live ads are not showing at all, I don't know what i am missing.
Here is code.
String.java XML
<!-- Insert Id admob -->
<string name="BannerAd_unit_id">cca-app-pub-1154915214031679/2100011458</string>
<string name="InterstitialAd_unit_id">ca-app-pub-1154915214031679/9049914448</string>
MainGame.Java Class
this.BANNER_AD_UNIT_ID = getResources().getString(R.string.BannerAd_unit_id);
showBanner();
screen java.class
public void showBanner() {
//banner ad
if (BANNER_AD_UNIT_ID.length() > 0) {
// Create an ad.
adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId(BANNER_AD_UNIT_ID);
//make ad visible on bottom of screen
RelativeLayout.LayoutParams params1 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params1.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
params1.addRule(RelativeLayout.CENTER_HORIZONTAL);
adView.setLayoutParams(params1);
layout.addView(adView);
// Create an ad request. Check logcat output for the hashed device ID to
// get test ads on a physical device.
AdRequest adRequest = new AdRequest.Builder()
//.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
//.addTestDevice("C01834A0B4A8FA4C03A0E09605F43819")//GalaxyS4*/
.build();
// Start loading the ad in the background.
adView.loadAd(adRequest);
}
}
If I Remove comment ".addTestDevice" Then testing ads are showing, if I comment it then live ads not showing. I don't know what is going on, any help will be appreciated.
If you're not receiving real ads, but are receiving 'test ads' then the implementation should be ok.
If you just created the ad account, it takes a few hours until real ads will appear and sometimes there might be no adds available to show.
Set an adListener to your adView and see what you're getting back. It might be a ERROR_CODE_NO_FILL or it might give you other hints to solve the problem.
Make sure you have updated AdMob with your payment details (go to Payments Section for that).
Check your AdMob dashboard to see the status of your ads to check if they are active.
Verify you used the correct Ad Unit Id.
After you update your info, it may take up to 24 hours to verify your information. After verification, they will enable your ad serving. You will get an email notification saying your ads are now being served.
If the test ads are working fine then your implementation is correct, but there is an option of "Payment" in the admob account which you need to fill. After filling up that form you will receive an email regarding the confirmation of payment details and message indicating that whether your information was accepted by the admob team or not if yes then your live ads will be showing up. But keep in mind that for the first few time the ad won't show up. it takes time to appear after the approval as well.
Here is the code snippet for the error code to find what is going wrong
mAdView = (com.google.android.gms.ads.AdView) findViewById(R.id.adView);
mAdView.setAdListener(new com.google.android.gms.ads.AdListener() {
#Override
public void onAdLoaded() {
// Code to be executed when an ad finishes loading.
Toast.makeText(HomeActivity.this, "onAdLoaded", Toast.LENGTH_SHORT).show();
}
#Override
public void onAdFailedToLoad(int errorCode) {
if(errorCode==AdRequest.ERROR_CODE_INTERNAL_ERROR)
Toast.makeText(HomeActivity.this, "onAdFailedToLoad", Toast.LENGTH_SHORT).show();
// Code to be executed when an ad request fails.
}
#Override
public void onAdOpened() {
Toast.makeText(HomeActivity.this, "onAdOpened", Toast.LENGTH_SHORT).show();
}
#Override
public void onAdLeftApplication() {
Toast.makeText(HomeActivity.this, "onAdLeftApplication", Toast.LENGTH_SHORT).show();
}
#Override
public void onAdClosed() {
Toast.makeText(HomeActivity.this, "onAdClosed", Toast.LENGTH_SHORT).show();
}
})
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
Get the error code:
ERROR_CODE_INTERNAL_ERROR - Something happened internally; for instance, an invalid response was received from the ad server.
ERROR_CODE_INVALID_REQUEST - The ad request was invalid; for instance, the ad unit ID was incorrect.
ERROR_CODE_NETWORK_ERROR - The ad request was unsuccessful due to network connectivity.
ERROR_CODE_NO_FILL - The ad request was successful, but no ad was returned due to lack of ad inventory.

Admob Not showing ads on real devices only showing on Test devices only

private void showInterstitialadd() {
mInterstitialAd = new InterstitialAd(MainActivity.this);
// set the ad unit ID
mInterstitialAd.setAdUnitId(getString(R.string.interstitial_full_screen));
AdRequest adRequest = new AdRequest.Builder()
.build();
// Load ads into Interstitial Ads
mInterstitialAd.loadAd(adRequest);
mInterstitialAd.setAdListener(new AdListener() {
public void onAdLoaded() {
showInterstitial();
}
});
}
private void showInterstitial() {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
}
}
I am using the above function for showing Ads....and its working absolutely fine on my test device but when I remove that .addTestdevice().....and run on any other devices it does not shows up....
There may be no issue in your code but AdMob doesn't show ads on real device quickly. You have to wait for few days. Before that, you have to enter some details like address and payment account detail in your AdMob account.
Don't worry they guide via email.
After you enter details, wait for few days, you will be notified in AdMob account that ads are showing.
In my case, it takes 2 days and, only Banner and Interstitial ads were activated at that time and video ads still do not get loaded.
So if ads are showing on test device then it will also be showing in the real device. The only thing you have to do is complete AdMob account setup and wait.
Also, don't forget to remove .addTestdevice() code before checking on real device.

Categories

Resources