Adding In-stream Ads to your Android app

Video publishers can now use Audience Network's In-stream solution to deliver video ads to their global audience across mobile and desktop environments in pre-roll and mid-roll settings. Follow this guide to display this type of ad unit for Android-based video content. For monetizing your web video content with in-stream ads, see the Web implementation guide. For in-stream video ads within iOS mobile apps, see the iOS implementation guide. Or see a list of available types.


Please refer to the "In-Stream Video Requirements" section of the Design Guidelines for Audience Network Ads.


This guide will walk you through implementing in-stream video ads on Android following these steps:

Step 1: Apply for Audience Network In-stream Video

Step 2: Create Placements

Step 3: Load and Show In-stream Video Ad

Ensure you have completed the Audience Network Getting Started and Android Getting Started guides before you proceed.

Step 1: Apply for Audience Network In-stream Video

Go to your app dashboard and from the Audience Network menu on the left side of the screen, select Apps and Websites. Then, go to the "Apply for in-stream video ads" section. Please review the Requirements and, if applicable, click on the Apply button and follow the on screen instructions.

Step 2: Create Placements

Audience Network offers 4 types of ad units: banner, interstitial (app only), native ads, and In-stream Video. You will see In-stream Video as a Display Format type after you have been approved for In-stream Video. Each ad unit in your app or website is identified using a unique placement ID. The first step in adding an ad unit is to create this identifier.

Click the Create Ad Placement button to start creating placement IDs to test in your video player.

In the Create Ad Placement form, enter a Name for your placement, information on how to invoke the ad in the Steps to Trigger Ad, and select In-stream Video as the Display Format.

Create a separate placement for each location in your website or app where you want to show ads. This will allow better insights tracking and performance calibration.

If you are using Audience Network In-stream Video for multiple properties such as desktop, mobile web, and mobile apps, be sure to name your placements accordingly (e.g. desktop_placement_1 and iOS_placement_1) as this will allow you to differentiate your placements and performance across platforms.

Once you click Save, you will see your new placement listed on the Placements tab.

To learn more about creating placements, please refer to our FAQ. To maximize your revenue, check out best practices for the Performance Optimization tool.

Step 3: Load and Show In-stream Video Ad

Ensure you have completed the Audience Network Getting Started and Android Getting Started guides before you proceed.

Add the following code at the top of your activity class in order to import the Facebook Ads SDK:


Next, instantiate an InstreamVideoAdView object and make a request to load an ad. This can also be done ahead of time, to pre-cache an ad response. In place of YOUR_PLACEMENT_ID, use the id of the in-stream video placement you created earlier.

When there is no ad to show, the onError will be called with error.code set to 1001. You should detect this and return to the content.

public class MainActivity extends AppCompatActivity {
  private InstreamVideoAdView adView;

  protected void onCreate(Bundle savedInstanceState) {


  private int pxToDP(int px) {
    return (int)(px / this.getResources().getDisplayMetrics().density);

  private void loadInstreamAd(){
    // Get the Ad Container
    LinearLayout adContainer = (LinearLayout) findViewById(;
    adView = new InstreamVideoAdView(
      new AdSize(
    // set ad listener to handle events
    adView.setAdListener(new InstreamVideoAdListener() {
      public void onAdLoaded(Ad ad) {
        // we have an ad so let's show it

      public void onAdVideoComplete(Ad ad) {


      public void onError(Ad ad, AdError adError) {


      public void onAdClicked(Ad ad) {


Finally, add the following code to your activity's onDestroy() function to release resources the adView use:

protected void onDestroy() {
  if (adView != null) {

When running on the simulator, test ads will be shown by default. To enable test ads on a device, add the following line of code before loading an ad: AdSettings.addTestDevice("HASHED ID");. Use the hashed ID that is printed to the log cat when you first make a request to load an ad on a device.

Hardware Acceleration for Video Ads

Videos ads in Audience Network requires the hardware accelerated rendering to be enabled, otherwise you might experience a black screen in the video views. This applies to

  • Videos creatives in Native Ads
  • Videos creatives in Interstitials
  • In-stream Video ads
  • Rewarded Videos

Hardware acceleration is enabled by default if your Target API level is >=14 (Ice Cream Sandwich, Android 4.0.1), but you can also explicitly enable this feature at the application level or activity level.

Application Level

In your Android manifest file, add the following attribute to the <application> tag to enable hardware acceleration for your entire application:

<application android:hardwareAccelerated="true" ...>

Activity Level

If you only want to enable the feature for specific activities in your application, in your Android manifest file, you can add the following feature to the <activity> tag. The following example will enable the hardware acceleration for the AudienceNetworkActivity which is used for rendering interstitial ads and rewarded videos:

<activity android:name="" android:hardwareAccelerated="true" .../>

Next Steps