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.

AmazonsNewLogo

 

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;
import com.amazon.device.ads.*;
import com.amazon.device.ads.AdListener;
import com.amazon.device.ads.AdSize;

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. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.loadUrl("file:///android_asset/www/index.html");
        LinearLayout linearLayout = new LinearLayout(this);
        linearLayout.setOrientation(LinearLayout.VERTICAL);
        ((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; 
         adView.setLayoutParams(lp);
        linearLayout.addView(adView);
        AdRegistration.enableLogging(true);
        AdRegistration.enableTesting(true);
        adView.setListener(this);

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

        linearLayout.addView(appView);

        setContentView(linearLayout);
        LoadAd();
    }

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

	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

	}

}

Manifest

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="com.amazon.device.ads.AdActivity" android:configChanges="keyboardHidden|orientation|screenSize"/>

Posted in Other

Tags:

Permalink 1 Comment

  • http://mircobabini.com/ Mirco Babini

    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.


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

  • wholesale nfl jerseys
  • wholesale nfl jerseys china
  • wholesale sports jerseys