# AlgoriX SDK Integration

# Step 1: Import SDK

# AAR/JAR library file integration

Copy the alx...*.aar from the SDK compression package to the Application Module/libs folder. If it doesn’t exist, create one manually. Then, add the following codes to build.gradle in your Module app:

//In Unity, the application folder is exported as unityLibrary
repositories {
    flatDir {
        dirs 'libs'
    }
}
depedencies {
    compile(name: 'alx.*.*.*', ext: 'aar') //replace with the specific sdk version number

}
1
2
3
4
5
6
7
8
9
10

# Step 2: Global Setting

# Permission Configuration

It’s recommended to obtain the following permissions configuration and state in your Privacy Policy that Alx SDK is allowed to gain access to these permissions.

<!—Required Permission -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!—Optional Permission -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
1
2
3
4
5
6
7

# Environment Configuration

The SDK can support Android 4.0 (API Level 14) and higher. <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="29" />

If developers use targetSdkVersion API 23 and higher, then ensure all permissions are added to the sdk before calling any API interfaces. Otherwise, certain features might not work.

# ProGuard Configuration

Add the following codes to the .pro file under the APP folder (For Android, the file is usually exported as proguard-rules.pro. For Unity, the file is exported as proguard-unity.txt):

  • keep class com.alxad.** {*;}
  • keep class admob.custom.adapter.** {*;}
  • keep class anythink.custom.adapter.** {*;}

# Step 3: Integration

First, please ask your account manager to create an sdk account on the AlgoriX Dashboard and provide you with a login information.

Then, create your app and placement, and get your Token, SID, APP_ID and Unit ID as shown below:

algorix_doc_01

SID=ID at AlgoriX Dashboard

algorix_doc_02

Unit ID=Placement ID

algorix_doc_03

Have your app initialize the ALX SDK by calling Application#onCreate()

// Token, SID, APP_ID

The account-related information can be retrieved from your AlgoriX account dashboard.

You can also contact your account manager to get the information

AlxAdSDK.init(this, AppConfig.ALX_TOKEN, AppConfig.ALX_SID, AppConfig.ALX_APP_ID, new AlxSdkInitCallback() {
     @Override
     public void onInit(boolean isOk, String msg) {

     }
});
1
2
3
4
5
6

Banner ads occupy a spot within an app's layout, either at the top or bottom of the device screen. They stay on screen while users are interacting with the app and can refresh automatically after a certain period of time.

  • Integration

  • Add AlxBannerAd to the layout

The first step toward displaying a banner is to place AlxBannerAd in the layout for the Activity or Fragment in which you'd like to display it. The easiest way to do this is to add one to the corresponding XML layout file. We also provide the ability to preload Banner ads.

Here's an example that shows an activity's AlxBannerAd

<com.alxad.api.AlxBannerAD
    android:id="@+id/alx_ad_banner"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true">
</com.alxad.api.AlxBannerAD>
1
2
3
4
5
6
7

If you need to preload ads, you can create a FrameLayout like below:

<FrameLayout
    android:id="@+id/ad_container"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="20dp" />
1
2
3
4
5
6

Here's an example that shows how to load an ad in the onCreate() method of an Activity:

public class AlxBannerDemoActivity extends AppCompatActivity implements
View.OnClickListener {
    private final String TAG = "AlxBannerDemoActivity";
    private AlxBannerAD alxBannerAD;
    //    private TextView mTvTitle;
    private Button mBnLoad;
    private Button mBnShow;
    private TextView mTvTip;
    private Button mBnLoadAndShow;
    private int adSize;
    private FrameLayout mAdContainer;
    private AlxBannerAD mAlxBannerView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_alx_banner_demo);
        if (getIntent() != null) {
            adSize = getIntent().getIntExtra("adsize", 0);
        }
        AlxBannerAD.AlxAdSize alxAdSize = adSize == 0 ? AlxBannerAD.AlxAdSize.SIZE_320_50 :
                adSize == 1 ? AlxBannerAD.AlxAdSize.SIZE_300_250 :
                        AlxBannerAD.AlxAdSize.SIZE_320_480;
        Log.d(TAG, "adsize : " + alxAdSize);
        setTitle("BannerAd  w_h:  " + alxAdSize);
        mTvTip = (TextView) findViewById(R.id.tv_tip);
        mBnLoad = (Button) findViewById(R.id.bn_load);
        mBnShow = (Button) findViewById(R.id.bn_show);
        mBnLoadAndShow = (Button) findViewById(R.id.bn_load_show);
        mAdContainer = (FrameLayout) findViewById(R.id.ad_container);
        mAlxBannerView = (AlxBannerAD) findViewById(R.id.alx_ad_banner);

        mBnLoad.setOnClickListener(this);
        mBnShow.setOnClickListener(this);
        mBnLoadAndShow.setOnClickListener(this);
        mBnShow.setEnabled(false);
    }

    @Override
    protected void onDestroy() {
        if (alxBannerAD != null) {
            alxBannerAD.destory();
        }
        if (mAlxBannerView != null) {
            mAlxBannerView.destory();
        }
        super.onDestroy();
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.bn_load:
                bnPreLoad();//Preload
                break;
            case R.id.bn_show:
                bnShow();//Display banner
                break;
            case R.id.bn_load_show:
                bnLoadAndShow();//Load and show
                break;
        }
    }

    private void bnPreLoad() {
        mBnLoad.setEnabled(false);
        alxBannerAD = new AlxBannerAD(this);
        AlxBannerAD.AlxAdSize alxAdSize = adSize == 0 ? AlxBannerAD.AlxAdSize.SIZE_320_50 :
                adSize == 1 ? AlxBannerAD.AlxAdSize.SIZE_300_250 :
                        AlxBannerAD.AlxAdSize.SIZE_320_480;
        alxBannerAD.setCanClosed(false);
        alxBannerAD.preLoad(this,AppConfig.ALX_BANNER_AD_PID, new AlxBannerADListener() {
            @Override
            public void onAdLoaded(AlxBannerAD banner) {
                Log.d(TAG, "onAdLoaded:" + Thread.currentThread().getName());
                mTvTip.setText("AlxBannerAD");
                mBnShow.setEnabled(true);
                mBnLoad.setEnabled(true);
            }

            @Override
            public void onAdError(AlxBannerAD banner, int errorCode, String errorMsg) {
                mBnShow.setEnabled(false);
                mBnLoad.setEnabled(true);
                mTvTip.setText("AlxBannerAD ");
                Log.d(TAG, "onAdError errorMsg:" + errorMsg + "  errorCode:" + errorCode + ":" + Thread.currentThread().getName());
            }

            @Override
            public void onAdClicked(AlxBannerAD banner) {
                Log.d(TAG, "onAdClicked ");
            }

            @Override
            public void onAdShow(AlxBannerAD banner) {
                Log.d(TAG, "onAdShow ");
            }

            @Override
            public void onAdClose() {
                Log.d(TAG, "onAdClose");
            }
        }, alxAdSize);
    }

    private void bnShow() {
        if (alxBannerAD != null && alxBannerAD.isReady()) {
            alxBannerAD.showAd(mAdContainer);
            mTvTip.setText("");
        }
    }

    private void bnLoadAndShow() {
        AlxBannerAD.AlxAdSize alxAdSize = adSize == 0 ? AlxBannerAD.AlxAdSize.SIZE_320_50 :
                adSize == 1 ? AlxBannerAD.AlxAdSize.SIZE_300_250 :
                        AlxBannerAD.AlxAdSize.SIZE_320_480;
        mAlxBannerView.setVisibility(View.VISIBLE);
        mAlxBannerView.setCanClosed(true);
        mAlxBannerView.load(this,AppConfig.ALX_BANNER_AD_PID, new AlxBannerADListener() {
            @Override
            public void onAdLoaded(AlxBannerAD banner) {
                Log.d(TAG, "onAdLoaded ");
            }

            @Override
            public void onAdError(AlxBannerAD banner, int errorCode, String errorMsg) {
                Log.d(TAG, "onAdError  errorMsg:" + errorMsg + "  errorCode:" + errorCode);
            }

            @Override
            public void onAdClicked(AlxBannerAD banner) {
                Log.d(TAG, "onAdClicked");
            }

            @Override
            public void onAdShow(AlxBannerAD banner) {
                Log.d(TAG, "onAdShow");
            }

            @Override
            public void onAdClose() {
                Log.d(TAG, "onAdClose");
            }
        }, alxAdSize);
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147

Here’s another example for Unity:

public class AlxBannerJavaDemoActivity extends AppCompatActivity {
    FrameLayout frameLayout;
    AlxBannerAD alxBannerAD;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        frameLayout = new FrameLayout(this);
        FrameLayout.LayoutParams		layoutParams	=	new	FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        layoutParams.gravity = Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL;
        frameLayout.setLayoutParams(layoutParams);
        setContentView(frameLayout);
        alxBannerAD = new AlxBannerAD(this);
        alxBannerAD.load(this,AppConfig.ALX_BANNER_AD_PID,new AlxBannerADListener() {
            @Override
            public void onAdLoaded(AlxBannerAD banner) {

            }
            @Override
            public void onAdError(AlxBannerAD banner, int errorCode, String errorMsg) {

            }
            @Override
            public void onAdClicked(AlxBannerAD banner) {

            }
            @Override
            public void onAdShow(AlxBannerAD banner) {
            }
        }, AlxBannerAD.AlxAdSize.SIZE_320_50);

        frameLayout.addView(alxBannerAD);
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

# Rewarded Video

OnReward () will be called back when the reward is issued. Developers can send a reward to users in the onReward callback.

Integration suggestions:

  1. Call the load method in advance to make an ad request so that it can be displayed quickly when the ad needs to be triggered.
  2. In the onRewardedVideoAdClosed callback, it is recommended to call the load method to make an ad request to facilitate the next ad display.
  3. Do not call the load method all the time in the onRewardedVideoAdFailed callback as this may cause the application to jam.

Code flow suggestions:

  1. Start the App or Game through AlxRewardVideoAd.load to load ads.
  2. When the Rewarded video needs to be displayed, determine whether it can be displayed by AlxRewardVideoAd.isReady false:Re-execute AlxRewardVideoAd.load to load ads true:Execute AlxRewardVideoAd.show to display the ads, and then execute AlxRewardVideoAd.load in the callback of onRewardedVideoAdClosed to preload the next Ads. (In the close callback, you can directly call load without the judgment of isReady, which helps increase the display volume of higher-priority advertising sources.)
  • Integration
//Create a RewardVideo object
AlxRewardVideoAD alxRewardVideoAD = new AlxRewardVideoAD();
// Load rewarded video ads
alxRewardVideoAD.load(this, mPid , new AlxRewardVideoADListener() { //mPid AlgoriX placement id
            @Override
            public void onRewardedVideoAdLoaded(AlxRewardVideoAD var1) {
                Log.i(TAG, "onRewardedVideoAdLoaded :" );
				showVideo(); //Show rewarded video ads
            }

            @Override
            public void onRewardedVideoAdFailed(AlxRewardVideoAD var1, int errCode, String errMsg) {
                Log.i(TAG, "onRewardedVideoAdFailed :" + errCode + " " + errMsg);
            }

            @Override
            public void onRewardedVideoAdPlayStart(AlxRewardVideoAD var1) {
                Log.i(TAG, " onRewardedVideoAdPlayStart :");
            }

            @Override
            public void onRewardedVideoAdPlayEnd(AlxRewardVideoAD var1) {
               Log.i(TAG, " onRewardedVideoAdPlayEnd :");
            }

            @Override
            public void onRewardedVideoAdPlayFailed(AlxRewardVideoAD var2, int errCode, String errMsg) {
               Log.i(TAG, " onRewardedVideoAdPlayFailed:"+errCode+";"+errMsg);
            }

            @Override
            public void onRewardedVideoAdClosed(AlxRewardVideoAD var1) {
                Log.i(TAG, " onRewardedVideoAdClosed :");
            }

            @Override
            public void onRewardedVideoAdPlayClicked(AlxRewardVideoAD var1) {
                Log.i(TAG, " onRewardedVideoAdPlayClicked :");
            }

            @Override
            public void onReward(AlxRewardVideoAD var1) {
                Log.i(TAG, " onReward :");
            }
        });

		public void showRewardVideo(){
		if (alxRewardVideoAD.isLoaded()) {
          alxRewardVideoAD.showVideo(this);
        }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
  • Interstitial

Interstitial ads are full-screen ads that cover the interface of their host app.

Integration suggestions:

  1. Call the load method in advance to make an ad request, so that it can be displayed quickly when the ad needs to be triggered.
  2. In the onInterstitialAdClose callback, it is recommended to call the load method to make an ad request to facilitate the next ad display.
  3. Do not call the load method all the time in the onInterstitialAdLoadFail callback. This may cause the application to jam.

Code flow suggestions:

  1. Start the app or game through AlxInterstitialAD.load to load ads
  2. When the Interstitial needs to be displayed, determine whether it can be displayed by AlxInterstitialAD.isRead false: Re-execute AlxInterstitialAD.load to load ads true: Execute AlxInterstitialAD.show to display the ads, and then execute AlxInterstitialAD.load in the callback of onInterstitialAdClose to preload the next Ads.
  • Integration
//Create an AlxInterstitialAD object
AlxInterstitialAD  alxInterstitialAD = new AlxInterstitialAD();
alxInterstitialAD.load(mContext, mPid, new AlxInterstitialADListener() { //mPid placement id
            @Override
            public void onInterstitialAdLoaded() {
                Log.d(TAG, "onInterstitialAdLoaded success");
                   If(alxInterstitialAD.isReady();){
                    alxInterstitialAD.show(MainActivity.this);//show interstitial ads

            }

            @Override
            public void onInterstitialAdLoadFail(int i, String s) {
                Log.d(TAG, "onInterstitialAdLoadFail " + "errorCode: " + i + " errorMSg: " + s);
            }

            @Override
            public void onInterstitialAdClicked() {
                Log.d(TAG, "onInterstitialAdClicked");
            }

            @Override
            public void onInterstitialAdShow() {
                Log.d(TAG, "onInterstitialAdShow");
            }

            @Override
            public void onInterstitialAdClose() {
                Log.d(TAG, "onInterstitialAdClose");
            }

            @Override
            public void onInterstitialAdVideoStart() {

            }

            @Override
            public void onInterstitialAdVideoEnd() {

            }

            @Override
            public void onInterstitialAdVideoError(int i, String s) {
                Log.d(TAG, "onInterstitialAdVideoError " + "errorCode: " + i + " errorMSg: " + s);
            }
        });
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

# Step 4: User Privacy

# 1. GDPR

AlgoriX is GDPR-compliant based on "legitimate interests," therefore the following functions are not mandatory. However, we offer these functions for those publishers who wish to pass consent information to AlgoriX. If the publisher implements these functions and the user does not consent, AlgoriX will serve non-interest-based content to that user.

# 2. CCPA

AlgoriX has features that help publishers comply with the California Consumer Privacy Act (CCPA). Note: If you are updating from a previous version of the AlgoriX SDK and have set privacy values using the old method, don’t worry. The new SDK will still read the previously set values, and you do not need to manually set them again. However, we would recommend eventually migrating your code to use this new method.

# 3. Implementation

This example shows the setting of all privacy flags (GDPR, user consent, below consent age, and US privacy).

AlxAdSDK.setSubjectToGDPR(true);
AlxAdSDK.setBelowConsentAge(true);
AlxAdSDK.setUserConsent("0");
AlxAdSDK.subjectToUSPrivacy("1YYY");
1
2
3
4

An optional "subject to GDPR" flag takes a Boolean value that can be set to YES/TRUE (if the user is subject to GDPR rules) or NO/FALSE (if the user is not subject to GDPR rules). This function should only be called if the application has made its own determination as to whether GDPR is applicable to the user or not. If this function is not called, AlgoriX assumes the application has not made such a determination, and therefore AlgoriX makes its own determination of GDPR applicability.

A belowConsentAge flag takes a Boolean value and can either be TRUE or FALSE. This flag can be used to inform us of COPPA compliance and GDPR age compliance. It will also inform AlgoriX’s ad tracking policy.

A setUserConsent function takes a string of either "0″ (user does not consent), "1″ (user does consent) or a more detailed consent string. This more detailed string is the consent string as described in the Transparency and Consent Framework as supported by the IAB.

Finally, this is the new USPrivacy flag. This flag takes a string value. The string that this flag takes is derived from the IAB’s US Privacy String Format and encodes the string in an enum.

1YNN where 1 is char in string for the version, Y = YES, N = No, – = Not Applicable See: IAB suggested US Privacy String Format

# Step 5: Error Code

Value Description
1100 Server Error. Please contact your AlgoriX Account Manager or Sales Engineer for further assistance
1101 An error in the network request. Check if the network status is normal
1102 No ads fill. Check sid and placement id, or contact your AlgoriX Account Manager or Sales Engineer for further assistance
1103 Bad ad creatives,check sid and placement id. Please contact your AlgoriX Account Manager or Sales Engineer for further assistance
1104 Server Error. Please contact your AlgoriX Account Manager or Sales Engineer for further assistance
1105 Server Error. Please contact your AlgoriX Account Manager or Sales Engineer for further assistance
1106 Video request failed, check if the network status is normal
1107 Video playback failed, check if the network status is normal
1108 Video download failed, unable to playback, check if the network status is normal
1109 Video file type not support,unable to playback. Please contact your AlgoriX Account Manager or Sales Engineer for further assistance
1110 Video file doesn’t exist,unable to playback. Please contact your AlgoriX Account Manager or Sales Engineer for further assistance
1111 Wrong parameter, unable to playback
1112 Ads rendered failed
1113 Sdk is not initialized
1017 Ads placement is not enabled by the AlgoriX admin. Please contact your AlgoriX Account Manager or Sales Engineer for further assistance.