Skip to content

Adnuntius Advertising

Jason Pell edited this page Mar 3, 2026 · 5 revisions

Visible and Viewable event changes in 1.10.0

The way the SDK generates visible and viewable events is changing starting with SDK version 1.7.0

https://github.com/Adnuntius/android_sdk/wiki/Visible-and-Viewable-Event-Handling

Embed ads into your app using the AdnuntiusAdWebView.

Add the AdnuntiusAdWebView to your xml layout file

<com.adnuntius.android.sdk.AdnuntiusAdWebView
        android:id="@+id/adView"
        android:layout_width="354dp"
        android:layout_height="244dp"
        android:layout_alignBottom="@+id/swipeRefreshLayout"
        android:layout_centerHorizontal="true"
        tools:ignore="MissingConstraints" />

Load Ad

In the Activity class load the web view in the onCreate (after calling setContentView), and then load the ad in the onResume, this will ensure that ads are reloaded when the app is paused and resumed.

The loadAd method accepts a CompletionHandler. This completion handler callback will be called asynchronously when the ad is either loaded into the webview or not, or when an error occurs.

A basic api for simple ad integrations, uses adn.js internally to render the ad and fire off all the right events.

    @Override
    protected void onResume() {
        super.onResume();
        AdRequest request = new AdRequest("000000000006f450")
                .noCookies()
                .addKeyValue("version", "4.3");

        adView.loadAd(request, false,
            new LoadAdHandler() {
                @Override
                public void onAdResponse(AdnuntiusAdWebView view, AdResponseInfo info) {
                    
                }

                @Override
                public void onNoAdResponse(AdnuntiusAdWebView view) {
                    // do something where no ad matches
                }
            
                @Override
                public void onFailure(AdnuntiusAdWebView view, String error) {
                   // do something on failure
                }
            });
    }

Close View from Layout

Its now possible to close a web view from an adnuntius layout via javascript.

If you want to be able to close ad view from javascript, its not possible to close the parent window from a layout due to the dreaded Scripts may close only the windows that were opened by them. So we have added a new method you can call from javascript which provides this functionality:

if (typeof parent.adnSdkHandler != "undefined") {
 parent.adnSdkHandler.closeView();
}

And the corresponding method in the LoadAdHandler:

   @Override
   public void onLayoutCloseView(AdnuntiusAdWebView view) {
        finish();
   }

Live Preview support

This is probably mostly useful for development, but if you want to force a line item / creative combo to appear in your web view.

    AdRequest request = new AdRequest("000000000006f450")
                .setWidth(300)
                .setHeight(200)
                .livePreview("line item id", "creative id")
                .noCookies()
                .addKeyValue("version", "4.3");

Parent parameter configuration

Possible to configure parent request parameters such as userId, sessionId and consentString into an ad request.

These values are passed onto the ad server request.

You can also specify other parent request parameters, such as gdpr:

    AdRequest request = new AdRequest("000000000006f450")
                .livePreview("line item id", "creative id")
                .userId("some user id")
                .sessionId("some user id")
                .consentString("some consent string")
                .parentParameter("gdpr", "0")
                .noCookies()
                .addKeyValue("version", "4.3");

Examples

An example app is available here: https://github.com/Adnuntius/android_sdk_examples

Clone this wiki locally