Adding advertising to your apps is easy. Integrating ads doesn’t require a major redesign of your app and has minimal impact on your app’s functionality. It is as simple as making space for the ad on the screen. The Amazon Mobile Ads API (Beta) enables you to display high-quality ads provided from the Amazon Mobile Ad Network in a matter of minutes. This article explains how to place ads into an existing app using the Amazon Mobile Ads API.
Set Up Your Payment Information
First and foremost, submit your payment information through the Payment Information Page and your tax information through the Tax Identity Interview. You can skip this step if you have already submitted this information through the Amazon Mobile App Distribution Portal. This is required to receive ads.
Retrieve Your Application Key
The Amazon Mobile Ads API utilizes a unique Application Key to identify and interact with an app. Every app will have its own Application Key. If your app is already on the Distribution Portal, you can find your Application Key on the app’s detail page. Otherwise, create a new app and fill in the “App title” and “Category” fields. Locate the Application Key value and set that aside. We will use that later to register with the Amazon Mobile Ad Network.
Incorporate the Amazon Mobile Ads API Into to Your Project
Next, you will need to add the Amazon Mobile Ads API to your project. For the purposes of this example, we will use Eclipse.
Download the Amazon Mobile Ads API (Beta) from here (this should link to our API landing page which has the file for download and the legal verbiage) and unzip it locally.
Add the JAR to Your Project
Modify the build path of your project and add the amazon-ads-<x.y.z>.jar found in the zip under the /Ads/lib folder.
- In the Eclipse project explorer, right-click on your project and open the properties
- Navigate to Java Build Path in the left pane
- Choose the “Libraries” section
- Press the “Add External JARs…” button
- Choose the amazon-ads-<x.y.z>.jar from the zip
- Choose the “Order and Export” section
- Check the box on the amazon-ads-<x.y.z>.jar
Add the amazon_ads_attr.xml to Your Project
This step is required to set up ads through the xml layout. Copy the amazon_ads_attr.xml file from the zip located in /Ads/res/values/ into your project’s res/values/ folder.
Modify the ApplicationManifest.xml
The Amazon Mobile Apps API requires the following permissions and activities:
- Add the following permissions to your manifest
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
- Add the following activities within the application tag
<activity android:name="com.amazon.device.ads.MraidBrowser" android:configChanges="keyboardHidden|orientation"/>
<activity android:name="com.amazon.device.ads.VideoActionHandler" android:configChanges="keyboardHidden|orientation|screenSize"/>
Place the Ad in Your Project Layout
Now that the project is set up to use the Amazon Mobile Ads API, the next step is to add an ad to the application layout.
- Open the layout xml you want to display your ads on from your project’s res/layout folder
- Add the following namespace to the parent layout filling in with your package name
- Add an AdLayout into your layout and configure the adSize attribute. You can find the supported ad size values here
- Set the layout_width and layout_height to match the adSize.
Modify Your Activity Code
Now we can call the Amazon Mobile Ads API to load ads.
Import the Ads Classes
Register with Your Application Key
Time to put that Application Key to work. In your activities onCreate, call the AdRegistration method to register your app and then call the Amazon Mobile Ads API to load an ad. Please note that you may only use an Application Key to display ads on the specific app for which it was issued.
//Register App with the Ad Network
//Load ad on to AdLayout
adview = (AdLayout)findViewById(R.id.adview);
Publish Your App
Submit your app to Amazon to display ads to your U.S. users and follow the attribution guidelines set forth here. The Amazon Mobile Ads API can also be used with apps that are distributed through any Android stores. Apps that use the Amazon Mobile Ads API may be distributed through any Android store as long as they are distributed through Amazon.
Your app is ready to display high-quality ads from the Amazon Mobile Ad Network. This is the simplest of configurations but the Amazon Mobile Ads API has several features for customizing your ad layout, ad targeting, error handling, debugging, and more. Read more about the many features of the Amazon Mobile Ads API (Beta) here.