Android SDK

This page describes how to install the AdGate Media iOS SDK.

Requirements

  • Android SDK minimum version 14 (Ice Cream Sandwich 4.0)

  • Minimum hardware requirement is ARMV7

  • Java JDK 1.6 or greater

1. Install SDK

Instructions provided here are for Android Studio. aar libraries are not yet supported on Eclipse, though some solutions are available online.

  1. Add the aar file to your project, by copying it into your project's libs folder.

  2. Add the following lines of code to your app's build.gradle file, so that Android Studio recognizes and builds the library along with your app.

repositories {
    flatDir {
        dirs 'libs'
    }
}

dependencies {
    implementation 'com.google.android.gms:play-services-iid:10.2.1'
    implementation 'com.google.android.gms:play-services-ads:10.2.1'
    implementation 'com.google.code.gson:gson:2.8.0'
    implementation 'com.squareup.okio:okio:1.12.0'
    implementation 'com.squareup.okhttp3:okhttp:3.7.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.facebook.network.connectionclass:connectionclass:1.0.1'
    implementation(name:'adgatemediasdk', ext:'aar')
}

At this point Android Studio shouldn't throw any errors related to the library.

2. Load the offer wall

  1. In your activity, where you intend to show the offer wall, add the following import statement:

import com.adgatemedia.sdk.classes.AdGateMedia;
  1. To load the offer wall, from any place in your running activity add the following code:

   final HashMap<String, String> subids = new HashMap<String, String>();
   subids.put("s2", "my sub id");
   AdGateMedia adGateMedia = AdGateMedia.getInstance();

   adGateMedia.loadOfferWall(YourActivity.this,
                   wallCode,
                   userId,
                   subids,
                   new OnOfferWallLoadSuccess() {
                       @Override
                       public void onOfferWallLoadSuccess() {
                           // Here you can call adGateMedia.showOfferWall();
                       }
                   },
                   new OnOfferWallLoadFailed() {
                       @Override
                       public void onOfferWallLoadFailed(String reason) {
                           // Here you handle the errors with provided reason
                       }
                   });

Remember to set wallCode and userId to the appropriate values. You can get your AdGate Rewards wall code from the Dashboard. The userId values can be any alphanumeric string. You may add up to 4 subid strings to the HashMap: s2, s3, s4, and s5.

3. Display the offer wall

Once offer wall is loaded you can display it by calling the showOfferWall method.

    AdGateMedia.getInstance().showOfferWall(YourActivity.this,
                                new AdGateMedia.OnOfferWallClosed() {
                                    @Override
                                    public void onOfferWallClosed() {
                                        // Here you handle the 'Offer wall has just been closed' event
                                    }
                                });

4. Get a list of the latest offer wall conversions

To get a list of latest offer wall conversions for a particular user run the following code in your activity:

   final HashMap<String, String> subids = new HashMap<String, String>();
   subids.put("s2", "my sub id");

   AdGateMedia.getInstance().getConversions(this, wallCode, userId, subids, new OnConversionsReceived() {
      @Override
      public void onSuccess(List<Conversion> conversions) {
          // Here you can loop through every conversion and process it.
          // conversions.size() holds the amount of new conversions to process.
          for (Conversion conversion : conversions)  {
              Log.i("AdGateRewards", "Received new conversion: " +
              "offer ID: " + String.valueOf(conversion.offerId) +
              " offer title: " + conversion.title +
              " transaction ID: " + conversion.txId +
              " points earned: " + String.valueOf(conversion.points) +
              " payout in cents:" + String.valueOf(conversion.payout) +
              " subid 2: "+conversion.subid2 +
              " subid 3: "+conversion.subid3 +
              " subid 4: "+conversion.subid4 +
              " subid 5: "+conversion.subid5
              );
          }
      }

      @Override
      public void onError(String message) {
          // Fired when any error occurs
      }
   });

The wallCode for your AdGate Rewards wall can be found on the AdGate Rewards panel page. The userId value is your app's internal user id for whom you'd like to check for conversions. subids is a hashmap of the subid's that was used when loading the offer wall.

If the call was successful, a list of conversions is passed to the onSuccess method. Each Conversion model has the following class definition:

public class Conversion implements Serializable {
    public int offerId;
    public String title;
    public String txId;
    public double points;
    public int payout; // in cents USD
    public String subid2;
    public String subid3;
    public String subid4;
    public String subid5;
}

6. Enable console messages

To enable debugging, warning, and error messages run the following line of code:

   AdGateMedia.getInstance().setDebugMode(true);

This will log messages to the console as well as to a log file. Make sure you disable debug mode before publishing your app to the Google Play Store.

7. Demo app

This repository contains a demo Android app that shows how to implement our SDK.

Last updated