Program Crashes when I try stuff with adverts

361 views
Skip to first unread message

Rewind

unread,
Aug 7, 2018, 8:48:16 AM8/7/18
to Google Mobile Ads SDK Developers
I have some xml

<com.google.android.gms.ads.AdView
 
android:id="@+id/adView"
 
android:layout_width="wrap_content"
 
android:layout_height="wrap_content"
 
app:layout_constraintLeft_toLeftOf="parent"
 
app:layout_constraintRight_toRightOf="parent"
 
app:layout_constraintBottom_toBottomOf="parent"
 
app:adSize="BANNER"
 
app:adUnitId="ca-app-pub-3940256099942544/6300978111"/>

I load an add after the European law stuff (this all works fine):

private void showPersonalizedAds() {
 
ConsentInformation.getInstance(this).setConsentStatus(ConsentStatus.PERSONALIZED);
 
AdView mAdView = findViewById(R.id.adView);
 
AdRequest adRequest = new AdRequest.Builder()
 
.addTestDevice(myDeviceIdForTestConsent) // Todo: Remove in Release build
 
.build();
 mAdView
.loadAd(adRequest);
}

Then after a user event on a webview I have in the same activity I do the following:

public void triggerAdvert() {
 
AdView adView;
 
AdSize adSize;

 
if(advertsOn) {
 adView
= findViewById(R.id.adView);
 adSize
= adView.getAdSize();
 
if(adSize != AdSize.LARGE_BANNER)
 adView
.setAdSize(AdSize.LARGE_BANNER);
 checkForConsent
();
 
}
}

The line adSize = adView.getAdSize() crashes it.

The checkForConsent() will check all the European law stuff again.

I am getting repeated weird stuff happen. I get crashes when I try and load an InterstitialAd. See here.

What am I doing so wrong with these adverts?

The advert only loads at start in a small banner, and everything else I try causes no end of problems.

mobileadssdk-a...@google.com

unread,
Aug 7, 2018, 3:45:22 PM8/7/18
to Rewind, Google Mobile Ads SDK Developers
Hi there,

Thanks for reaching out to us. We would be happy to assist you with the issue, but first can you go through our sample apps  and the guides and see if you are missing something with your implementation? If you are still having trouble after going through the sample apps, can you please share a sample app with your implementation so that we will take a look and assist you further? You can use "Reply Privately to Author" option to share the details privately.

Regards,
Deepika Uragayala
Mobile Ads SDK Team
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+ page:
    http://googleadsdeveloper.blogspot.com
    https://plus.google.com/115658573333388777174/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

--

---
You received this message because you are subscribed to the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To post to this group, send email to google-admob-ads-sdk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-admob-ads-sdk/467e5487-ba4f-485d-8214-03c05b1afea9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rewind

unread,
Aug 7, 2018, 7:08:17 PM8/7/18
to google-adm...@googlegroups.com
Hi, I have tried to strip as much as possible to show the problem.

1.Start a new project, with an Empty Activity. Company name: www.testappadverts.com, Application Name: TestAppAdverts, just Phone and Tablet with API 19.
2. Update or create the files below.
3. In the debugger put breakpoints on MainActivity.java lines; 305, 373 and 379.
4. Let the program load.
5. The European stuff about GDPR dialog should come up. (I am in the UK, so you may need to force yourself to be in the EU.)
6. Click the top one saying personal advertising.
7, Wait and an ad comes up at the bottom in the white bar. Everything OK so far.
8. Now click the button on the Webpage saying 'Trigger Full Page Advert'.
9. The breakpoints will lead you through. It gets to the code to display a full advert, but does nothing.

(Note in the triggerAdvert function in MainAtivity, when I set m_NextAdvertFullScreen = false; and unhash the adView and adSize code, it should increase the BANNER ad size, but just crashes instead.)

I tried to upload the whole project, but it has memory limits, so here are all the files:

app|java|com.testappadverts.www.testappadverts|MainActivity.java

package com.testappadverts.www.testappadverts;

import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;

import com.google.ads.consent.ConsentForm;
import com.google.ads.consent.ConsentFormListener;
import com.google.ads.consent.ConsentInfoUpdateListener;
import com.google.ads.consent.ConsentInformation;
import com.google.ads.consent.ConsentStatus;
import com.google.ads.mediation.admob.AdMobAdapter;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.ads.MobileAds;

import java.net.MalformedURLException;
import java.net.URL;

public class MainActivity extends AppCompatActivity {

// MUST REMOVE FOR RELEASE
private static final String myDeviceIdForTestConsent = "8CE710413B34F4BB57DDD60BD1D880D6"; // Search for // Todo: Remove in Release build

// Keep a reference here
WebAppInterface webInterface;

// This is the page advert
boolean advertsOn = true;
long minutesDay = 24 * 60;
long minutesLastPageAdvert = 0;
private InterstitialAd mInterstitialAd;

// This is the consent form
private ConsentForm form;
private boolean m_NextAdvertFullScreen = false;

@Override
protected void onCreate(Bundle savedInstanceState) {
// This if want to hide title bar
//requestWindowFeature(Window.FEATURE_NO_TITLE); // This seems to have no effect
// Instead in app|res|value|styles.xml change
// <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
// To <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
// The following FLAG_FULLSCREEN gets rid of the battery etc info at top
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// The GDPR consent
// https://gist.github.com/ameerhamza6733/36d88c6a74c9ae6dd7b6355cee0d5de7
checkForConsent();

WebView webview = (WebView) findViewById(R.id.webView);
WebSettings settings = webview.getSettings();
settings.setJavaScriptEnabled(true);
webview.setWebChromeClient(new WebChromeClient());
webview.loadUrl("file:///android_asset/www/index.html?IsAndroidWebview=true"); // This is a cheat to tell the html we are calling in AndroidApp
//webview.loadUrl("file:///android_asset/www/index.html"); // This is a cheat to tell the html we are calling in AndroidApp
// These things allegedly make it faster
settings.setLoadWithOverviewMode(true);
settings.setUseWideViewPort(true);
settings.setSupportZoom(true);
settings.setBuiltInZoomControls(false);
//settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
settings.setDomStorageEnabled(true);
webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webview.setScrollbarFadingEnabled(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
webview.setLayerType(View.LAYER_TYPE_HARDWARE, null);
} else {
webview.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}

webInterface = new WebAppInterface(this, webview);
webview.addJavascriptInterface(webInterface, "Android");

// Adverts
// Must do this before the billing is initialized,
// So getIAP will be able to work on the advert
AdView adView;
String myAdModAppId = "ca-app-pub-3940256099942544~3347511713"; // This is for testing
MobileAds.initialize(this, myAdModAppId);
// This is when you add your adview programatically - it needs to be added to the webview
//adView = new AdView(this);
//adView.setAdSize(AdSize.BANNER);
//adView.setAdUnitId("ca-app-pub-3940256099942544/6300978111"); // Each context should have a new id
// Load an advert
/*
adView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
adView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
// Code to be executed when an ad finishes loading.
}
@Override
public void onAdFailedToLoad(int errorCode) {
// Code to be executed when an ad request fails.
}
@Override
public void onAdOpened() {
// Code to be executed when an ad opens an overlay that
// covers the screen.
}
@Override
public void onAdLeftApplication() {
// Code to be executed when the user has left the app.
}
@Override
public void onAdClosed() {
// Code to be executed when when the user is about to return
// to the app after tapping on an ad.

//View view = getView();
//if (view != null) {
// Toast.makeText(getView().getContext(), "Thank you for tapping an advert.", Toast.LENGTH_SHORT).show();
//}
Window win;
Context cont;
if((win = getWindow()) != null && (cont = win.getContext()) != null) {
Toast.makeText(cont, "Thank you for tapping an advert.", Toast.LENGTH_SHORT).show();
}
}
});
*/
// This is the page advert
/*
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
// Load it at start, so it is ready
mInterstitialAd.loadAd(new AdRequest.Builder().build());
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
// Code to be executed when an ad finishes loading.
}
@Override
public void onAdFailedToLoad(int errorCode) {
// Code to be executed when an ad request fails.
}
@Override
public void onAdOpened() {
// Code to be executed when the ad is displayed.

// Turn off the game loop
}
@Override
public void onAdLeftApplication() {
// Code to be executed when the user has left the app.
}
@Override
public void onAdClosed() {
// Code to be executed when when the interstitial ad is closed.

// This method is invoked when when the interstitial ad is closed
// due to the user tapping on the close icon or using the back button.
// If your app paused its audio output or game loop,
// this is a great place to resume it.

// Get the next advert to load
mInterstitialAd.loadAd(new AdRequest.Builder().build());
}
});
*/
}

// --- Adverts ---

public void turnAdvertsOnOff(boolean on) {
AdView adView = (AdView) this.findViewById(R.id.adView);
AdRequest adRequest;

if(on){
advertsOn = true;
adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
adView.setVisibility(View.VISIBLE);
}else {
advertsOn = false;
adView.destroy();
adView.setVisibility(View.GONE);
}
}

public void loadPageAdvert() {
long minutes = System.currentTimeMillis() / (60000);
if (minutes > (minutesDay + minutesLastPageAdvert)){
//mInterstitialAd.isLoaded()) {
minutesLastPageAdvert = minutes;
mInterstitialAd.show();
}
}

// --- Advert Consent ---

private void checkForConsent() {
ConsentInformation consentInformation = ConsentInformation.getInstance(MainActivity.this);
String[] publisherIds = {"pub-id-from-publishers-like-admob"};
consentInformation.requestConsentInfoUpdate(publisherIds, new ConsentInfoUpdateListener() {
@Override
public void onConsentInfoUpdated(ConsentStatus consentStatus) {
// User's consent status successfully updated.
switch (consentStatus) {
case PERSONALIZED:
showPersonalizedAds();
break;
case NON_PERSONALIZED:
showNonPersonalizedAds();
break;
case UNKNOWN:
if (ConsentInformation.getInstance(getBaseContext())
.isRequestLocationInEeaOrUnknown()) {
requestConsent();
} else {
showPersonalizedAds();
}
break;
default:
break;
}
}

@Override
public void onFailedToUpdateConsentInfo(String errorDescription) {
// User's consent status failed to update.
}
});
}

private void requestConsent() {
URL privacyUrl = null;
try {
privacyUrl = new URL("http://www.chartmygolf.com/privacy.html");
} catch (MalformedURLException e) {
//e.printStackTrace();
// Handle error.
}
form = new ConsentForm.Builder(MainActivity.this, privacyUrl)
.withListener(new ConsentFormListener() {
@Override
public void onConsentFormLoaded() {
// Consent form loaded successfully.
showForm();
}

@Override
public void onConsentFormOpened() {
// Consent form was displayed.
}

@Override
public void onConsentFormClosed(
ConsentStatus consentStatus, Boolean userPrefersAdFree) {
if (userPrefersAdFree) {
// Buy or Subscribe

//webInterface.returnToHtmlOnMyMenu("divInAppPurchase");
} else {
switch (consentStatus) {
case PERSONALIZED:
showPersonalizedAds();break;
case NON_PERSONALIZED:
showNonPersonalizedAds();break;
case UNKNOWN:
showNonPersonalizedAds();break;
}
}
// Consent form was closed.
}

@Override
public void onConsentFormError(String errorDescription) {
// Consent form error.
}
})
.withPersonalizedAdsOption()
.withNonPersonalizedAdsOption()
.withAdFreeOption()
.build();
form.load();
}

/*
want test your app watch this video https://youtu.be/_JOapnq8hrs?t=654
*/
private void showPersonalizedAds() {
/* this line code save consent status if you want to show your ads in next activty just get getConsentStatus and load ads accouding to status e.g.
MainActivty2 ConsentStatus consentStatus =ConsentInformation.getInstance(this).getConsentStatus();
if (consentStatus.toString().equals("NON_PERSONALIZED")) loadNonPersonlizedAds(); i hateeeeeeeeeet This new policy
*/
ConsentInformation.getInstance(this).setConsentStatus(ConsentStatus.PERSONALIZED);

if(m_NextAdvertFullScreen) {
m_NextAdvertFullScreen = false;
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("Add_unit");
mInterstitialAd.loadAd(new AdRequest.Builder()

.addTestDevice(myDeviceIdForTestConsent) // Todo: Remove in Release build
                    .build());
}else {

AdView mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(myDeviceIdForTestConsent) // Todo: Remove in Release build
.build();
mAdView.loadAd(adRequest);
}

        // if you want to show interstital
/*
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("Add_unit");
mInterstitialAd.loadAd(new AdRequest.Builder().addTestDevice(DEVICE_TEST_ID).build());

*/
}

private void showNonPersonalizedAds() {
ConsentInformation.getInstance(this).setConsentStatus(ConsentStatus.NON_PERSONALIZED);

if(m_NextAdvertFullScreen){
m_NextAdvertFullScreen = false;
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("Add_unit");
mInterstitialAd.loadAd(new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class,
getNonPersonalizedAdsBundle())

.addTestDevice(myDeviceIdForTestConsent) // Todo: Remove in Release build
                        .build());
}else {

AdView mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(myDeviceIdForTestConsent) // Todo: Remove in Release build
                    .addNetworkExtrasBundle(AdMobAdapter.class, getNonPersonalizedAdsBundle())
.build();
mAdView.loadAd(adRequest);
}

/* if you want show interstitial ad also
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("Add_unit");
mInterstitialAd.loadAd(new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class, getNonPersonalizedAdsBundle()).addTestDevice(DEVICE_TEST_ID).build());

*/

}
public Bundle getNonPersonalizedAdsBundle() {
Bundle extras = new Bundle();
extras.putString("npa", "1");

return extras;
}
private void showForm() {
if (form != null) {
//Log.d(TAG, "Showing consent form");
form.show();

}
}

public void triggerAdvert() {
AdView adView;
AdSize adSize;

if(advertsOn) {
        //    adView = findViewById(R.id.adView);
// adSize = adView.getAdSize();
// if(adSize != AdSize.LARGE_BANNER)
// adView.setAdSize(AdSize.LARGE_BANNER);
m_NextAdvertFullScreen = true;
checkForConsent();
}
}
}

app|java|com.testappadverts.www.testappadverts|MainActivity.java

package com.testappadverts.www.testappadverts;

import android.content.Context;
import android.webkit.WebView;

public class WebAppInterface {
Context mContext;
//private final Callback callback;
WebView webview;

/**
* Instantiate the interface and set the context
*/
WebAppInterface(Context c, WebView w) {
mContext = c;
//this.callback = callback;
webview = w;
}

// --- This to trigger a new major advert update ---

@android.webkit.JavascriptInterface
public void triggerAdvert() {
((MainActivity) mContext).triggerAdvert();
}
}

app|manifests|AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.testappadverts.www.testappadverts">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>

app|assets|www|index.html

<!DOCTYPE html>

<html>
<head>
<title>Thought Provoking Title</title>

<!-- This following line is for mobiles, it makes sure they work properly -->
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />

</head>

<!-- Thought this would stop zooming but it does not -ms-content-zooming: none | zoom; -->
<body style="width:100%; height: 100%; padding: 0 0 0 0; margin: 0 0 0 0; overflow: hidden; background:#FFAAAA; font-family: 'Arial', sans-serif;">

<div>
<h3>A Thought Provoking Title</h3>
<p>Great words of profound wisdom.</p>
<button onclick="Android.triggerAdvert();">Trigger Full Page Advert</button>
</div>

</body>
</html>

app|res|layout|activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<WebView
android:id="@+id/webView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="5dp"
app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintBottom_toTopOf="@+id/adView" />

<!-- "BANNER" or "LARGE_BANNER" -->
    <com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:adSize="BANNER"
app:adUnitId="ca-app-pub-3940256099942544/6300978111"/>

</android.support.constraint.ConstraintLayout>

GradleScripts|app


apply plugin: 'com.android.application'

android {
compileSdkVersion 28
defaultConfig {
applicationId "com.testappadverts.www.testappadverts"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

repositories {
mavenCentral()
}

dependencies {
/* This is for adverts */
implementation 'com.google.android.gms:play-services-ads:15.0.0'
/* Consent for Adverts GDPR */
implementation 'com.google.android.ads.consent:consent-library:1.0.6'

implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

mobileadssdk-a...@google.com

unread,
Aug 8, 2018, 3:12:11 PM8/8/18
to Rewind, Google Mobile Ads SDK Developers
Hi there,

Thank you for the code snippets. The getAdSize() must be called when onAdLoaded() has been fired by the SDK and not before that. You must have null checker while doing so. From the code snippets, it looks like you are calling the getAdSize() as soon as the user triggers the action for the WebView. You must instead make the AdRequest and wait for the onAdLoaded() callback via AdListener to retrieve the AdSize. Let us know if you need anything else.


Regards,
Deepika Uragayala
Mobile Ads SDK Team
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+ page:
    http://googleadsdeveloper.blogspot.com
    https://plus.google.com/115658573333388777174/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

On 08/07/18 19:08:16 jonas...@gmail.com wrote:
Hi, I have tried to strip as much as possible to show the problem.

1. In the debugger put breakpoints on MainActivity.java lines; 305, 373 and 379.
2. Let the program load.
3. The European stuff about GDPR dialog should come up. (I am in the UK, so you may need to force yourself to be in the EU.)
4. Click the top one saying personal advertising.
5, Wait and an ad comes up at the bottom in the white bar. Everything OK so far.
6. Now click the button on the Webpage saying 'Trigger Full Page Advert'.
7. The breakpoints will lead you through. It gets to the code to display a full advert, but does nothing.

Rewind

unread,
Aug 8, 2018, 3:42:11 PM8/8/18
to google-adm...@googlegroups.com
Thanks for the reply Deepika.

The getAdSize() thing was just an afterthought, not the main problem. This has been hashed out. The program as written still does not work, even with the hash outs.

The main problem is I cannot get a full page advert to show.

In the MainAvtivity code:

1. triggerAdvert() is called
2. This calls checkForConsent()
3. When you have already gone through the EU code it calls the section `case PERSONALIZED: showPersonalizedAds(); break;`
4. This is turn calls the section (because we have set the m_NextAdvertFullScreen flag as true)

if(m_NextAdvertFullScreen){
m_NextAdvertFullScreen = false;
mInterstitialAd = new InterstitialAd(this);

mInterstitialAd.setAdUnitId("Add_unit");
mInterstitialAd.loadAd(new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class,
getNonPersonalizedAdsBundle())
.addTestDevice(myDeviceIdForTestConsent) // Todo: Remove in Release build
.build());
}

5. This should display a full page advert, but does not.


Rewind

unread,
Aug 9, 2018, 8:38:11 AM8/9/18
to google-adm...@googlegroups.com
Is it anything to do with the line

mInterstitialAd.setAdUnitId("Add_unit");

I have changed it to

mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");

but it still does not work. This code was the Interstitial test code from the page:

https://developers.google.com/admob/android/test-ads

I have also made the following edits, to check to see if the ad loads:


if(m_NextAdvertFullScreen) {
m_NextAdvertFullScreen = false;
mInterstitialAd = new InterstitialAd(this);
    mInterstitialAd.setAdUnitId(adIdInterstial);
mInterstitialAd.loadAd(new AdRequest.Builder()
//.addTestDevice(myDeviceIdForTestConsent) // Todo: Remove in Release build
.build());

mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
// Code to be executed when an ad finishes loading.
}
@Override
public void onAdFailedToLoad(int errorCode) {
// Code to be executed when an ad request fails.
}
@Override
public void onAdOpened() {
// Code to be executed when the ad is displayed.

// Turn off the game loop
}
@Override
public void onAdLeftApplication() {
// Code to be executed when the user has left the app.
}
@Override
public void onAdClosed() {
// Code to be executed when when the interstitial ad is closed.

// This method is invoked when when the interstitial ad is closed
// due to the user tapping on the close icon or using the back button.
// If your app paused its audio output or game loop,
// this is a great place to resume it.

            // Get the next advert to load
mInterstitialAd.loadAd(new AdRequest.Builder().build());
}
});

After doing this I can confirm the ad is definitely loading as it calls the function:

public void onAdLoaded()

So why is the ad not showing? Is there some xml stuff I have to write as a container for the ad? I thought these Interstitial ads did not need any xml.

Please help, I am so confused.

mobileadssdk-a...@google.com

unread,
Aug 9, 2018, 3:23:30 PM8/9/18
to Rewind, Google Mobile Ads SDK Developers
Hi there,

The InterstitialAd does not need an XML layout since it's an Activity on its own. Checking your code snippet again, when are you calling the loadPageAdvert() function to present the loaded InterstitialAd? You can call this as soon as onAdLoaded() is fired by the SDK. Make sure to call mInterstitialAd.show() to present the InterstitialAd to your user.

Regards,
Deepika Uragayala
Mobile Ads SDK Team
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+ page:
    http://googleadsdeveloper.blogspot.com
    https://plus.google.com/115658573333388777174/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

On 08/09/18 08:38:11 jonas...@gmail.com wrote:
Is it anything to do with the line

mInterstitialAd.setAdUnitId("Add_unit");

What do I need for a test advert?


On Wednesday, August 8, 2018 at 8:42:11 PM UTC+1, Rewind wrote:
Thanks for the reply Deepika.

The getAdSize() thing was just an afterthought, not the main problem. This has been hashed out. The program as written still does not work, even with the hash outs.

The main problem is I cannot get a full page advert to show.

In the MainAvtivity code:

1. triggerAdvert() is called
2. This calls checkForConsent()
3. When you have already gone through the EU code it calls the section `case PERSONALIZED: showPersonalizedAds(); break;`
4. This is turn calls the section (because we have set the m_NextAdvertFullScreen flag as true)

if(m_NextAdvertFullScreen){
m_NextAdvertFullScreen = false;
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("Add_unit");
mInterstitialAd.loadAd(new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class,
getNonPersonalizedAdsBundle())
.addTestDevice(myDeviceIdForTestConsent) // Todo: Remove in Release build
.build());
}

5. This should display a full page advert, but does not.


--

---
You received this message because you are subscribed to the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To post to this group, send email to google-admob-ads-sdk@googlegroups.com.

Rewind

unread,
Aug 9, 2018, 3:39:47 PM8/9/18
to Google Mobile Ads SDK Developers

Thankyou, thankyou, thankyou.

I did not realise you had to call mInterstitialAd.show().

Now I know this, I think I will rework my code to load the full page advert early, so it is immediately ready when I want it.

Thank you once again. You are great.

(loadPageAdvert() was just a secondry function I had not used yet. The calls to get a full page add were done through the EU GDRP stuff, either calling
showPersonalizedAds() or showNonPersonalizedAds().)
Reply all
Reply to author
Forward
0 new messages