How to add Amazon Mobile Ads to a Phonegap app

Here is how to add Amazon Mobile Ads. I will give a review after I see some results.

3 Steps to adds Amazon ads to Phonegap

  1. Download the SDK
  2. Add jar to your project (screen shots below)
  3. Change your Activity and Manifest as below. No need to change layout.



Screen Shots adding jar to Eclipse project

Screen Shot 2013-08-30 at 3.58.54 PM Screen Shot 2013-08-30 at 3.59.31 PM Screen Shot 2013-08-30 at 3.59.53 PM Screen Shot 2013-08-30 at 4.00.02 PM




Activity Code

Do not for get to change your application id and set ‘debug’ and ‘logging’ to true.

package org.www.hello;

import org.apache.cordova.*;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.os.Handler;

public class HelloCordovaActivity extends DroidGap implements AdListener {

    private Handler mHandler = new Handler(); 
    private AdLayout adView; // The ad view used to load and display the ad.
    private static final String APP_KEY = "sample-app-v1_pub-2"; // Sample Application Key. Replace this variable with your Application Key
    private static final String LOG_TAG = "SimpleAdSample"; // Tag used to prefix all log messages

    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        LinearLayout linearLayout = new LinearLayout(this);
        ((ViewGroup) appView.getParent()).removeView(appView);
        adView = new AdLayout(this,AdSize.SIZE_300x50);
         LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,          LinearLayout.LayoutParams.WRAP_CONTENT);
         lp.gravity= Gravity.BOTTOM; 

        try {
        } catch (Exception e) {
        Log.e(LOG_TAG, "Exception thrown: " + e.toString());



     * Load a new ad.
    public void LoadAd() { 
        // Load the ad with the appropriate ad targeting options.
        AdTargetingOptions adOptions = new AdTargetingOptions();

	public void onAdCollapsed(AdLayout arg0) {
		// TODO Auto-generated method stub


	public void onAdExpanded(AdLayout arg0) {
		// TODO Auto-generated method stub


	public void onAdFailedToLoad(AdLayout arg0, AdError arg1) {
		// TODO Auto-generated method stub


	public void onAdLoaded(AdLayout arg0, AdProperties arg1) {
		// TODO Auto-generated method stub




Add these permission 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 this right before your closing application tag.

      <activity android:name="" android:configChanges="keyboardHidden|orientation|screenSize"/>

Posted by in Other


Permalink 1 Comment

One response to “How to add Amazon Mobile Ads to a Phonegap app

  1. Cool, but the ad is always placed at the top, instead of the bottom of the screen. Sadly.

    EDIT: just figured out how to place it at the bottom of the screen. It’s just in the order you add the views to the linearLayout.

    Thanks, it’s just perfect.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Graveyard Database Logo

Has everything you want to know about grave yards. Plus has many celebrites and world leaders graves. Pssst it is my other site

Google + Profile
Check out Android Photo Mapping, its a app/site I been working on
Fabulou wholesale Petr Mrazek jersey is back. Best choice to get the wholesale Petr Mrazek jersey is suitable for all style of people.