PlayHaven is a real-time mobile game marketing platform which helps you take control of the business of your games.
An API token and secret is required to use this SDK. Visit the PlayHaven developer dashboard at https://dashboard.playhaven.com.
Integrating the Playhaven Android SDK is dead simple and should take no more than a minute.
Note: If you are developing your game using Unity, this instructions are irrelevant and you should use the Playhaven Unity SDK located here.
-
Download the Playhaven SDK here and ensure you have the latest version of the Android Developer Tools installed.
-
Install the SDK into your project.
-
Set the API keys you received from the dashboard. Although you can set these wherever you wish, we advise the root
Activity
.
PHConfig.token = "your token"
PHConfig.secret = "your secret"
- Add the main ad display to your
AndroidManifest.xml
file.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET"/>
<activity android:name="com.playhaven.src.publishersdk.content.PHContentView" android:theme="@android:style/Theme.Dialog"></activity>
This guide assumes you have followed the installation instructions above.
Purpose: helps the server track game usage.
Notes: Make sure to pass in a Context
(usually an Activity
) to the PHPublisherOpenRequest
constructor.
PHPublisherOpenRequest request = new PHPublisherOpenRequest([your context]);
request.send();
Purpose: Displays a fullscreen ad unit with the placement specified.
Notes: Make sure to provide the PHPublisherContentRequest
constructor with a valid Context
(usually an Activity
). You can specify placements in the Playhaven dashboard.
PHPublisherContentRequest request = new PHPublisherContentRequest([your context], "your placement");
request.send();
Purpose: Displays a small badge with a number indicating the number of new games a user can view.
Notes: You may place this anywhere in your app but we've found the best solution is to add it to an button which then launches a PHPublisherContentRequest
with a "more_games" placement. Once a user clicks on the button you should call clear()
on the notification view to reset the badge number.
PHNotificationView notifyView = new PHNotificationView([your context], "your placement");
[your button/view/layout].addView(notifyView);
notifyView.refresh();
Purpose: Allows your game to respond when the users unlocks rewards you have configured in the dashboard.
Notes: You must set the RewardDelegate
on a PHPublisherContentRequest
object to receive this callback. See the Callbacks section below for more information.
public void unlockedReward(PHPublisherContentRequest request, PHReward reward) {
... your handling code here...
}
The PHReward object has the following useful properties:
- name: The reward's name (specified in the dashboard)
- quantity: The reward's amount (specified in the dashboard)
Every type of request in the Playhaven Android SDK has a special "delegate" you can set to receive "callbacks" as the request progresses. You can find more information regarding the delegate pattern here.
You must implement the appropriate delegate interface from the list below and then add your object as a delegate. Most often the root Activity
should handle the callbacks.
Once you've implemented the appropriate callbacks you must set the delegate on the individual request before sending:
PHPublisherOpenRequest request = new PHPublisherOpenRequest([your context]);
request.delegate = [your delegate (usually an Activity)]
request.send();
Note: There are several delegate interfaces for a PHPublisherContentRequest
. You should implement the ones which provide relevant callbacks.
- FailureDelegate
- CustomizeDelegate
- RewardDelegate
- ContentDelegate
When working with the multiple delegates in PHPublisherContentRequest
:
PHPublisherContentRequest request = new PHPublisherContentRequest([your context (usually Activity)], "your placement");
request.content_delegate = [your customize delegate];
request.customize_delegate = [your customize delegate];
request.failure_delegate = [your failure delegate];
request.reward_delegate = [your reward delegate];
request.send();
- failure of request:
public void didFail(PHPublisherContentRequest request, String error) {
... your handling code here ...
}
- failure of actual ad:
public void contentDidFail(PHPublisherContentRequest request, Exception e) {
... your handling code here ...
}
- customize the close button:
public Bitmap closeButton(PHPublisherContentRequest request, PHButtonState state) {
... return a custom bitmap for the given state ...
}
- customize the border color:
public int borderColor(PHPublisherContentRequest request, PHContent content) {}
... constant from the Color class ...
}
- unlocked a reward:
public void unlockedReward(PHPublisherContentRequest request, PHReward reward) {
... handle the reward in-game ...
}
- ad content is downloading:
public void willGetContent(PHPublisherContentRequest request) {
... your handling code here ...
}
- ad content is going to display:
public void willDisplayContent(PHPublisherContentRequest request, PHContent content) {
... return a custom bitmap for the given state ...
}
- ad content has been shown:
public void didDisplayContent(PHPublisherContentRequest request, PHContent content) {
... your handling code here ...
}
- ad was dismissed:
public void didDismissContent(PHPublisherContentRequest request, PHDismissType type) {
... your handling code here ...
}
- successful request callback:
public void requestSucceeded(PHAPIRequest request, JSONObject responseData) {
... your handling code here ...
}
- unsuccessful request callback:
public void requestFailed(PHAPIRequest request, Exception e) {
...your handling code here...
}
A few helpful tips on using the Playhaven Android SDK.
This special method within PHPublisherContentRequest
is helpful when you wish to determine if your game is resuming after showing an ad or from another app entirely. The timerange argument should be specified in milliseconds and we generally find that about 2 seconds (2000 milliseconds) works best. An example onResume
handler using this feature:
@Override
public void onResume() {
super.onResume();
if (PHPublisherContentRequest.didDismissContentWithin(2000)) { // can actually be less than 2 seconds, all we want is enough time for onResume to be called
System.out.println("Resumed after displaying ad unit");
return;
}
System.out.println("Resumed after other app was shown");
}