Android Open Source - tapad-android-sdk Ad Serving






From Project

Back to project page tapad-android-sdk.

License

The source code is released under:

MIT License

If you think the Android project tapad-android-sdk listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.tapad.adserving;
/*w ww . j  a v a2 s.co  m*/
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.webkit.WebView;
import com.tapad.tracking.Tracking;

/**
 * Main entry point for ad serving API users. Provides API initialization as well
 * as access to the ad serving service which allows for fetching raw HTML markup.
 *
 * The init method must be invoked regardless of whether the managed ad views
 * are used or if the API user want to access the markup directly.
 */
public class AdServing {
    private static AdServingService service;

    /**
     * Initializes the ad serving API with publisher and property ids as specified in
     * AndroidManifest.xml:
     *
     * <application>
     *  <meta-data android:name="swappit.PUBLISHER_ID" android:value="INSERT_PUBLISHER_ID_HERE"/>
     *  <meta-data android:name="swappit.PROPERTY_ID" android:value="INSERT_PROPERTY_ID_HERE"/>
     *  ...
     * </application>
     *
     * @param context     a context reference
     */
    public static void init(Context context) {
        try {
            ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
            Object publisherId = ai.metaData.get("swappit.PUBLISHER_ID");
            if (publisherId == null) throw new RuntimeException("swappit.PUBLISHER_ID is not set in AndroidManifest.xml");

            Object propertyId = ai.metaData.get("swappit.PROPERTY_ID");
            if (propertyId== null) throw new RuntimeException("swappit.PROPERTY_ID is not set in AndroidManifest.xml");

            init(context, publisherId.toString(), propertyId.toString());
        } catch (Exception e) {
            throw new RuntimeException("Unable to read swappit.PUBLISHER_ID and swappit.PROPERTY_ID from AndroidManifest.xml");
        }

    }

    /**
    * Initializes the ad serving API with a publisherId and propertyId.
    *
    * @param context     a context reference
    * @param publisherId the publisher specific id as specified by Tapad
    * @param propertyId  the app specific id as specified by Tapad
    */
    public static void init(Context context, String publisherId, String propertyId) {
        WebView wv = new WebView(context);
        String userAgent = wv.getSettings().getUserAgentString();
        wv.destroy();

        Tracking.init(context, propertyId, null);
        AdResource resource = new AdResource(Tracking.getDeviceId(), publisherId, propertyId, userAgent);
        service = new AdServingServiceImpl(new AdRequestDispatcher(resource, 2));
    }

    /**
     * Get a reference to the ad serving service. Please invoke AdServing.init() first to initialize the ad
     * serving API.
     *
     * @return the ad serving service
     * @throws IllegalStateException if the API has not been initialized.
     */
    public static AdServingService get() {
        if (service == null)
            throw new IllegalStateException("Please call AdServing.init(context, publisherId, propertyId) to initialize the API first!");
        else return service;
    }
}




Java Source Code List

com.tapad.adserving.AdRequestDispatcher.java
com.tapad.adserving.AdRequest.java
com.tapad.adserving.AdResource.java
com.tapad.adserving.AdResponse.java
com.tapad.adserving.AdServingServiceImpl.java
com.tapad.adserving.AdServingService.java
com.tapad.adserving.AdServing.java
com.tapad.adserving.AdSize.java
com.tapad.adserving.ui.AdView.java
com.tapad.sample.AdViewActivity.java
com.tapad.sample.MainActivity.java
com.tapad.sample.MainApplication.java
com.tapad.sample.ManualMarkupActivity.java
com.tapad.sample.SampleConstants.java
com.tapad.tracking.DeviceIdentifier.java
com.tapad.tracking.DeviceInfo.java
com.tapad.tracking.EventDispatcher.java
com.tapad.tracking.EventResource.java
com.tapad.tracking.Event.java
com.tapad.tracking.InstallReferrerReceiver.java
com.tapad.tracking.TrackingServiceImpl.java
com.tapad.tracking.TrackingService.java
com.tapad.tracking.Tracking.java
com.tapad.tracking.deviceidentification.AndroidId.java
com.tapad.tracking.deviceidentification.IdentifierSourceAggregator.java
com.tapad.tracking.deviceidentification.IdentifierSource.java
com.tapad.tracking.deviceidentification.PhoneId.java
com.tapad.tracking.deviceidentification.TypedIdentifier.java
com.tapad.tracking.deviceidentification.WifiMac.java
com.tapad.util.DigestUtil.java
com.tapad.util.HttpClientUtil.java
com.tapad.util.IoUtil.java
com.tapad.util.Logging.java