Get Started

Prerequisites

  • The Android PAL SDK.

Create a new application, and add the Android PAL SDK as a library.

Generate a Nonce

A "nonce" is a value intended to be used once and only once. The PAL SDK allows you to generate a nonce that can be used to request programmatic ads. All of the code snippets below are modifications to MyActivity.java.

import android.app.Activity;
import android.os.Bundle;
import com.google.ads.interactivemedia.pal.NonceGenerator;
import com.google.ads.interactivemedia.pal.NonceGenerator.NonceGeneratorCallback;
import com.google.ads.interactivemedia.pal.NonceGeneratorException;


public class MainActivity extends Activity {
...
  private NonceGenerator nonceGenerator;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    nonceGenerator = new NonceGenerator();
    ...
  }

  public void generateNonceForAdRequest() {
    nonceGenerator.setDescriptionURL("https://example.com/content1");
    nonceGenerator.setOmidVersion("1.0.0");
    nonceGenerator.setOmidPartner("Example Publisher");
    nonceGenerator.setPlayerType("ExamplePlayerType");
    nonceGenerator.setPlayerVersion("1.0.0");
    nonceGenerator.setPpid("testPpid");
    nonceGenerator.setVideoPlayerHeight(480);
    nonceGenerator.setVideoPlayerWidth(640);
    nonceGenerator.setWillAdAutoPlay(true);
    nonceGenerator.setWillAdPlayMuted(true);
    nonceGenerator.registerNonceGeneratorCallback(new NonceCallbackImpl());
    nonceGenerator.generateNonce();
  }

  private static class NonceCallbackImpl implements NonceGeneratorCallback {
    @Override
    public void onNonceGeneration(String nonceString) {
      Log.i("PALSample", "Generated nonce: " + nonceString);
    }

    @Override
    public void onNonceGenerationFailure(NonceGeneratorException error) {
      Log.e("PALSample", "Nonce generation failed: " + error.getMessage());
    }
  }
}

Once a nonce is generated, it will be passed back to you in onNonceGeneration(). When making your direct VAST call (DVC), set this nonce as the value on the paln parameter. The nonce is URL safe—you don't need to URL-encode it.