Getting started

Here is how you can start using our API in 5 minutes.

  • Sign up as a publisher

    http://manager.moonkey.net/signup.html

    sign up moonkey
  • Register a new app

    Fill in your Play Store URL at My Apps

    new app moonkey
  • Set a new content for your app

    Fill in your content parameters at Contents

    new content moonkey
  • Add AndroidMoonkit SDK

    Go to Android Studio | New Project | Minimum SDK

    Select API 15: Android 4.0.3 or higher and create your new project.

    After you create a new project, open your_app | build.gradle

    Open Build Gradle
    Open build.gradle

    Add this to Module-level /app/build.gradle before dependencies:

    
    
    repositories {
    mavenCentral()
    }

    Add the compile dependency with the latest version of the AndroidMoonkit SDK in the build.gradle file:

    
    
    dependencies { 
      compile 'net.moonkey.androidmoonkit:androidmoonkit:1.+'
    }
    
    
    
  • Add the code to your Activity and Layout XML files

    Click on the "" icon corresponding to your content

    Contents Code Moonkey

    Copy & Paste your Moonkey code in your Activity and Layout XML files (examples below)

    
    
    import net.moonkey.androidmoonkit.MoonkeyButton;
    import net.moonkey.androidmoonkit.MoonkeyCallback;
    import net.moonkey.androidmoonkit.MoonkeyContent;
    
    /* ... */
    
    public class MainActivity extends Activity {
    
        /* ... */
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            moonkeyContent = new MoonkeyContent();
            moonkeyContent.connect(this, new HashMap() {{
                    put("clientId", "3690030126");
                    put("contentIdentifier", "4277378542");
                    put("version", "1.0");
                    put("lang", "en_US");
                }}, new MoonkeyCallback() {
    
                    @Override
                    public void onSuccess(String transactionId, String accessToken) {
                        Log.i("AndroidMooonkit","onSuccess called. TransactionId : "
                        
    + transactionId + ". AccessToken : " + accessToken); } @Override public void onClose() { Log.i("AndroidMooonkit","onClose called."); } @Override public void onMoonkeyShow() { Log.i("AndroidMooonkit","onMoonkeyShow called."); } @Override public void onMoonkeyHide() { Log.i("AndroidMooonkit","onMoonkeyHide called."); } }); MoonkeyButton moonkeyButton = (MoonkeyButton) findViewById(R.id.moonkeyButton); if(moonkeyButton != null) moonkeyButton.setContent(moonkeyContent); } }
    
    
    <net.moonkey.androidmoonkit.MoonkeyButton
    android:id="@+id/moonkeyButton" android:layout_width="250dp" android:layout_height="100dp" android:clickable="true" moonkey:moonkeyType="button" moonkey:moonkeyBorderWidth="3" moonkey:moonkeyBorderRadius="3" moonkey:moonkeyBorderColor="#FFF" moonkey:moonkeyBackgroundColor="#0FFF" moonkey:moonkeyText="Unlock with Moonkey" moonkey:moonkeyTextSize="18" moonkey:moonkeyTextColor="#FFF" />
  • Choose your placement type

    Click here to see different ways of displaying the Moonkey solution in your app.

  • Test the Moonkey solution

    Activate the "Debug mode" in the Apps/Websites page

    Debug Mode Moonkey

    Using this mode, you will be able to unlock your content without any advertising. It allows you to test your solution and the associated settings.
    Do not use "Debug Mode" in production environment.

Placement types

Choose the Moonkey solution you want on your app.

Custom button

Create your custom button with the following parameters by setting moonkey:moonkeyType to "button"

Parameters : moonkeyBorderWidth | moonkeyBorderRadius | moonkeyBorderColor | moonkeyBackgroundColor | moonkeyText | moonkeyTextSize | moonkeyTextColor

Custom button
Custom button example

<net.moonkey.androidmoonkit.MoonkeyButton
android:id="@+id/moonkeyButton"
android:layout_width="250dp" android:layout_height="100dp" android:clickable="true"
moonkey:moonkeyType="button"
moonkey:moonkeyBorderWidth="3"
moonkey:moonkeyBorderRadius="3"
moonkey:moonkeyBorderColor="#FFF"
moonkey:moonkeyBackgroundColor="#0FFF"
moonkey:moonkeyText="Unlock with Moonkey"
moonkey:moonkeyTextSize="18"
moonkey:moonkeyTextColor="#FFF"
/>

Image button

Choose an image to use as a button by setting moonkey:moonkeyType to "image" and android:background to your image.


Image button
Image button example

<net.moonkey.androidmoonkit.MoonkeyButton
android:id="@+id/moonkeyButton"
android:layout_width="100dp"
android:layout_height="100dp"
android:clickable="true"
android:background="@drawable/my_image"
moonkey:moonkeyType="image"
/>

Webview

Display the Moonkey solution as it would be on a website by setting moonkey:moonkeyType to "webview"

This is the button that will be automatically displayed if there is no other button attribute defined when using a webview.

Webview default button
Webview default button

<net.moonkey.androidmoonkit.MoonkeyButton
android:id="@+id/moonkeyButton"
android:layout_width="350dp"
android:layout_height="100dp"
android:clickable="true"
moonkey:moonkeyType="webview"
/>
Customize your Moonkey button by setting your image URL.

Webview custom button
Webview custom button

<net.moonkey.androidmoonkit.MoonkeyButton
android:id="@+id/moonkeyButton"
android:layout_width="350dp"
android:layout_height="100dp"
android:clickable="true"
moonkey:moonkeyType="webview"
moonkey:moonkeyImgSrc="http://www.mywebsite.com/.../mycustombutton.png" />
Choose our paywall to get a complete solution.

Webview default paywall
Webview default paywall

<net.moonkey.androidmoonkit.MoonkeyButton
android:id="@+id/moonkeyButton"
android:layout_width="350dp"
android:layout_height="400dp"
android:clickable="true"
moonkey:moonkeyType="webview"
moonkey:moonkeyPaywall="true"
/>
Customize your paywall by changing the introduction message and the button.

Webview custom paywall
Webview custom paywall

<net.moonkey.androidmoonkit.MoonkeyButton
android:id="@+id/moonkeyButton"
android:layout_width="350dp"
android:layout_height="400dp"
android:clickable="true"
moonkey:moonkeyType="webview"
moonkey:moonkeyPaywall="true"
moonkey:moonkeyPaywallIntro="My custom introduction" moonkey:moonkeyImgSrc="http://www.mywebsite.com/.../mycustombutton.png" />

Events

Success

Function : onSuccess
Fired when a user has unlocked your content.


@Override
public void onSuccess(String transactionId, String accessToken) {
    Log.i("AndroidMooonkit","onSuccess called. TransactionId : " + transactionId + ". AccessToken : " + accessToken);
}

Close

Function : onClose
Fired when a user comes back from Moonkey platform without unlocking your content.


@Override
public void onClose() {
    Log.i("AndroidMooonkit","onClose called.");
}

MoonkeyShow

Function : onMoonkeyShow
Fired when Moonkey button access is granted.


@Override
public void onMoonkeyShow() {
    Log.i("AndroidMooonkit","onMoonkeyShow called.");
}

MoonkeyHide

Function : onMoonkeyHide
Fired when Moonkey button access is denied.


@Override
public void onMoonkeyHide() {
    Log.i("AndroidMooonkit","onMoonkeyHide called.");
}

Server-to-server validation (optional)

  • Get the transactionId and the accessToken from the onSuccess Callback
  • Send a request to your server with the transactionId and the accessToken
  • Send an HTTP POST request from your server to the Moonkey servers with the transactionId and the accessToken
  • POST parameters to send : transactionId | accessToken
  • Parse the JSON response to check the validity of the transaction
  • - status | Value : 0 (Valid accessToken) - 1 (Invalid accessToken) - 2 (Debug accessToken)
    - message | Value : a message describing the request
    - data (status = 0 only)
    * application | Value : name of the app/website
    * price | Value : price of the content
    * floor_price | Value : floor price of the content
    * date | Value : date of the transaction

    Example of valid accessToken response :
    
    {
    	status: 0,
    	message: "Access Token is valid.",
    	data: {
    		application: "Fleex",
    		price: "0.10",
    		floor_price: "0.02",
    		date: "2017-01-01"
    	}
    }
    

    Example of invalid accessToken response :
    
    {
    	status: 1,
    	message: "Invalid Access Token."
    }
    

    If the API request is wrong, you will get something like :
    
    {
    	error: {
    		message: "You must send a transactionId and an accessToken.",
    		request: {
    			method: "verifyAccessToken"
    		}
    	}
    }
    
  • Give your user access to the premium content.

Advanced Configuration

All configuration parameters have to be included in the HashMap as follows :

/* ... */
/* John Doe's profile */
String userGender = "male";

Calendar cal = Calendar.getInstance();
cal.set(1976, Calendar.APRIL, 13);
String userBirthday = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());

String userChildDirectedTreatment = "false";

String userLocation = "{}";
try {
    JSONObject geolocation = new JSONObject();
    geolocation.put("latitude", "37.422");
    geolocation.put("longitude", "-122.084");
    geolocation.put("accuracy", "10");
    userLocation = geolocation.toString();
} catch (JSONException e) {}

/* ... */
moonkeyContent.connect(this, new HashMap() {{
    put("clientId", "1811141408");
    put("contentIdentifier", "3226246716");
    put("version", "1.0");
    put("gender", userGender);
    put("birthday", userBirthday);
    put("childDirectedTreatment", userChildDirectedTreatment);
    put("geolocation", userLocation);
}}, new MoonkeyCallback() {});

/* ... */


User gender

Key : gender

Type : Enum
Default : unknown
Values : male | female | unknown

	put("gender", "female");

/* ... */
/* John Doe's profile */
String userGender = "male";

/* ... */
moonkeyContent.connect(this, new HashMap() {{
    put("clientId", "1811141408");
    put("contentIdentifier", "3226246716");
    put("version", "1.0");
    put("gender", userGender);
}}, new MoonkeyCallback() {});

/* ... */

User birthday

Key : birthday

Type : String (date formatted like yyyy-MM-dd)

put("birthday", "1976-04-13");

/* ... */
/* John Doe's profile */
Calendar cal = Calendar.getInstance();
cal.set(1976, Calendar.APRIL, 13);
String userBirthday = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());

/* ... */
moonkeyContent.connect(this, new HashMap() {{
    put("clientId", "1811141408");
    put("contentIdentifier", "3226246716");
    put("version", "1.0");
    put("birthday", userBirthday);
}}, new MoonkeyCallback() {});

/* ... */

Child treatment

Key : childTreatmentDirected
Set to indicate you want Moonkey to treat your content as child-directed

Type : Enum
Default : false
Values : true | false


	put("childDirectedTreatment", "false");



/* ... */
/* John Doe's profile */
String userChildDirectedTreatment = "false";

/* ... */
moonkeyContent.connect(this, new HashMap() {{
    put("clientId", "1811141408");
    put("contentIdentifier", "3226246716");
    put("version", "1.0");
    put("childDirectedTreatment", userChildDirectedTreatment);
}}, new MoonkeyCallback() {});

/* ... */

User location

Key : geolocation
Set to enable geolocated ads

Type : JSON String
Parameters : latitude | longitude | accuracy

put("geolocation", "{\"latitude\":37.422,\"longitude\":-122.084,\"accuracy\":10}");

/* ... */
/* John Doe's profile */
String userLocation = "{}";
try {
    JSONObject geolocation = new JSONObject();
    geolocation.put("latitude", "37.422");
    geolocation.put("longitude", "-122.084");
    geolocation.put("accuracy", "10");
    userLocation = geolocation.toString();
} catch (JSONException e) {}

/* ... */
moonkeyContent.connect(this, new HashMap() {{
    put("clientId", "1811141408");
    put("contentIdentifier", "3226246716");
    put("version", "1.0");
    put("geolocation", userLocation);
}}, new MoonkeyCallback() {});

/*...*/