Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Navitabs
usewithoutbodytrue
rootDTSA:Location Marketing SDK (iOS)

 

Version 2.1.1

This is Phunware's Android SDK for the MaaS Advertising module. Visit http://maas.phunware.com/ for more details and to sign up.

Requirements

  • MaaS Core v1.3.2 or greater
  • Google Play services to enable Advertising ID support (recommended); installation instructions here

Getting Started

  • Download MaaS Advertising and run the included sample app.
  • Continue reading below for installation and integration instructions.
  • Be sure to read the documentation for additional details.

Installation

The following libraries are required:

No Format
MaaSCore.jar

MaaS Advertising has a dependency on MaaSCore.jar, which is available here: https://github.com/phunware/maas-core-android-sdk

It's recommended that you add the MaaS libraries to the 'libs' directory. This directory should contain MaaSCore.jar and MaaSMaaSAdvertising.jar, as well as any other MaaS libraries that you are using.

Update your AndroidManifest.xml to include the following permissions and activity:

Code Block
themeMidnight
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

<!-- Optional permissions to enable ad geotargeting:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
-->

<!-- Inside of the application tag: -->
<activity
    android:name="com.phunware.advertising.internal.PwAdActivity"
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize" />

See AndroidManifest.xml for an example manifest file.

Documentation

The documentation is included in HTML format (in the Docs folder) and zipped as well. 

Integration

The primary methods in MaaS Advertising involve displaying the various ad types:

Native Ad Usage

Native ads are advertisements designed to fit naturally into your app's look and feel. Predefined ad features are provided as a JSON payload which your app consumes in a template that follows your UI's theme.

Code Block
themeMidnight
languagejava
import com.phunware.advertising.*;

// ...


String zoneId = "YOURNATIVEADZONEID"; 
PwNativeAd nativeAd = PwAdvertisingModule.get().getNativeAdForZone(context, zoneId); 
nativeAd.setListener(new PwNativeAd.PwNativeAdListener() { 
	@Override 
	public void nativeAdDidLoad(PwNativeAd nativeAd) { 
		try { 
			renderUiFromNativeAd(nativeAd);


		} catch (JSONException e) {
            // Log the error and discard this native ad instance.
        }
    }

    @Override
    public void nativeAdDidFail(PwNativeAd nativeAd, String errMsg) {
        // The ad failed to load and the errMsg willdescribes describe why.
        // Error messages are not intended for user display.
    }
});

nativeAd.load();

// ...

// ... when native ad data is displayed on screen: 
nativeAd.trackImpression();

// ...
 
// ... when native ad is clicked: 
nativeAd.click(context);
Code Block
themeMidnight
private void renderUiFromNativeAd(PwNativeAd nativeAd) throws JSONException {
    JSONObject json = new JSONObject(nativeAd.getAdData());
    String adtitle = json.optString("adtitle");
    String imageurl = json.optString("iconurl");
    double stars = json.optDouble("rating");
    String html = json.optString("html");
    String adtext = json.optString("adtext");
    String cta = json.optString("cta");

    // Use the data to build a view item of your own design.
}

To request multiple ads at once:

Code Block
themeMidnight
languagejava
String zoneId = "YOURNATIVEADZONEID"; 
PwAdRequest request = PwAdvertisingModule.get().getAdRequestForZone(zoneId);

PwAdvertisingModule.get().getNativeAdLoader(); 
int numberOfAdsToLoad = 10; 
PwAdLoader<PwNativeAd> adLoader = PwAdvertisingModule.get().getNativeAdLoader();

adLoader.multiLoad(context, request, numberOfAdsToLoad, 
	new PwAdLoader.PwAdLoaderListener<PwNativeAd>() { 
		@Override 
		public void onSuccess(PwAdLoader adLoader, List<PwNativeAd> nativeAdsList) { 
			for(PwNativeAd nativeAd : nativeAdsList) { 
				// ToUse use the native ad to build a view item.
				try { 
					renderUiFromNativeAd(nativeAd); 
				} catch (JSONException e) { 
					// Log the error and discard this native ad instance.
				} 
			} 
		}
 
		@Override
        public void onFail(PwAdLoader adLoader, String errMsg) {
            // No ads are returned and the errMsg willdescribes describe why.
            // Error messages are not intended for user display.
        }
    }
);

Code samples and advanced implementation can be found in the Native Ad Example Code native ad example code. Gradle project: Native Ad Example Project

Banner Usage

Banners are inline ads that are shown alongside your app's interface.

Note

For XML usage only. 

Add this to your layout xml:

Code Block
themeMidnight
<!-- Add a banner to your layout xml. --> 
<!-- This will cause a 320x50 ad to be created, which will automatically kick off ad rotation. --> 
<com.phunware.advertising.PwBannerAdView 
	android:id="@+id/bannerAd" 
	android:layout_width="320dp" 
	android:layout_height="50dp" 
	zone="YOUR_ZONE_ID" />

Add this to your layout .xml (note that "zone" is not specified):

Code Block
themeMidnight
<!-- Add a banner to your layout xml. --> 
<!-- This will cause a 320x50 ad to be created, which will automatically kick off ad rotation. --> 
<com.phunware.advertising.PwBannerAdView 
	android:id="@+id/bannerAd" 
	android:layout_width="320dp" 
	android:layout_height="50dp" />

Add this to your activity:

Code Block
themeMidnight
languagejava
import com.phunware.advertising.*;
 
// ...

 
PwBannerAdView bannerAdView = (PwBannerAdView)findViewById(R.id.bannerAd); 
bannerAdView.startRequestingAdsForZone("YOURBANNERZONE_ID");

Advanced implementation can be found in the example code.

Interstitial Usage

Interstitial ads are best used at discrete stopping points in your app's flow, such as at the end of a game level or when the player dies.

Code Block
themeMidnight
languagejava
import com.phunware.advertising.*;

// ...

PwInterstitialAd interstitialAd = PwAdvertisingModule.get().getInterstitialAdForZone(this, "YOURINTERSTITIALZONE_ID"); interstitialAd.show();

Advanced implementation can be found in the example code.

Video Ads Usage

Video ads are interstitial ads that play a video. They are best used at discrete stopping points in your app's flow, such as at the end of a game level or when the player dies.

Code Block
themeMidnight
languagejava
import com.phunware.advertising.*;


// ...


PwVideoInterstitialAd videoAd = PwAdvertisingModule.get().getVideoInterstitialAdForZone(this, "YOURVIDEOZONE_ID"); videoAd.show(); 

Advanced implementation can be found in the example code.

ON THIS PAGE

Table of Contents