Getting Started For Android 1.8.4
Index
1、Import TGSDK to the project
Copy TGSDK files to the project
First, download the latest and TGSDK official version from yomob Official Website SDK Download Page After decompression, you can view the directory structure shown in the following figure.

Using Gradle with Android Studio to create the project
If you use Android Studio or Gradle to create your Android project, then you only need to import all aar
files under TGSDK folder into your project.
Using Eclipse Ant to create the project
If you use Eclipse or Ant to create your Android project, then you only need to import all files under subfolder of for_eclipse
in TGSDK folder into your project.
Add dependencies
Some Ad Networks require thirdparty libraries. Therefore, you need to import these dependencies into your project. These dependency files are under dependencies
folder.
Note: Please import all the dependency files into your project, or else the program might crash due to missing dependency files
All dependency files are jar
type, if you need to use Android Studio for your project and need to use Gradle to manage your project dependency without using jar
files,you can follow the below steps to import the dependencies into your project.
First add jcenter
into the repositories
of build.gradle
under the main project of your project.
buildscript {
repositories {
mavenCentral();
// ******** Add jcenter ********
jcenter()
// ******** Add google ********
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
}
}
allprojects {
repositories {
// ******** Add jcenter ********
jcenter()
// ******** Add google ********
google()
}
}
Then add the dependencies config under the build.gradle
file in the Module
.
dependencies {
compile 'com.squareup.okio:okio:1.14.0'
compile 'com.squareup.okhttp3:okhttp:3.10.0'
// require GooglePlayService
compile 'com.google.android.gms:play-services-ads:15.0.1'
compile 'com.google.android.gms:play-services-ads-base:15.0.1'
compile 'com.google.android.gms:play-services-ads-identifier:15.0.1'
compile 'com.google.android.gms:play-services-location:15.0.1'
compile 'com.google.android.gms:play-services-basement:15.0.1'
compile 'com.google.android.gms:play-services-gass:15.0.1'
// by Facebook
compile 'com.android.support:recyclerview-v7:25.3.1'
// by Vungle
compile 'com.tonyodev.fetch:fetch:1.1.5'
compile 'com.squareup.okhttp3:logging-interceptor:3.7.0'
compile 'com.squareup.retrofit2:retrofit:2.2.0'
compile 'com.squareup.retrofit2:converter-gson:2.2.0'
compile 'com.google.code.gson:gson:2.6'
//by bytedance
compile 'pl.droidsonroids.gif:android-gif-drawable:1.2.6'
// by Oneway
compile 'com.liulishuo.okdownload:okdownload:1.0.5'
compile 'com.liulishuo.okdownload:sqlite:1.0.5'
compile 'com.liulishuo.okdownload:okhttp:1.0.5'
}
Add Android Support V4 library
Note: Android Support v4 is a forced dependency,please include it into your project. The version of the Android Support v4 lib has to be above v26, or else the build might encounter issues!
Some Ad networks require android.support.v4
lib. Therefore, please import the library into your project. If your project uses Android Studio, then you can edit project build.gradle
file and add:
dependencies {
compile 'com.android.support:support-v4:24.+'
}
If your project uses Eclipse or Unity,the TGSDK version v1.6.2 or above v4 support lib by default。If you use TGSDK version below v1.6.2,you have to add v4 support lib manually. You can find the aar
library under Android SDK
with path below:
Your-Android-SDK-Path/extras/android/m2repository/com/android/support/support-v4
Add support for Google Play Service
If your App is for the Google Play Store. Then you need to import Google Play Services since some Ads networks require the support of this service.
The Google Play Service is only needed for publishing your App into Google Play store. If you only publish your App into Chinese Android App Stores, you don't need to include Google Play Services
For details regarding Google Play Services integration, please refer to Google Official Developer Guides。
Note: You don't need to import all Google Play Service libraries into your project. The libraries required are as below:
com.google.android.gms:play-services-ads-15.0.1
com.google.android.gms:play-services-ads-base-15.0.1
com.google.android.gms:play-services-ads-identifier-15.0.1
com.google.android.gms:play-services-ads-lite-15.0.1
com.google.android.gms:play-services-location-15.0.1
com.google.android.gms:play-services-basement-15.0.1
About Android 7.0 permissions
-
-
Before copying sdk, you must copy and paste the contents of the
uses_provider.txt
file into the<application>
node inAndroidManifest.xml
.Eclipse developers need to replace
${applicationId}
in the file with the package name of app
-
-
2.Confuse the configuration file by adding:
-keep class android.support.v4.*{ ;}
Avoid confusion with FileProvider code in support-V4 packages.
Modify AndroidManifest.xml file
Eclipse developers please copy and paste content from android_manifest.txt
file into AndroidManifest.xml
file in your project between
All developers please copy the content of uses_permissions.txt
file and paste it into the AndroidManifest.xml
file in your project,while <uses-permission>
node is at the same level of <application>
node.
<application>
<activity>
......
</activity>
</application>
<uses-permission android:name="xxxx" />
<uses-permission android:name="xxxx" />
<uses-permission android:name="xxxx" />
If using Proguard
If your project uses proguard
,you need to copy and paste content from proguard-project.txt
file into the proguard
configuration file in your project.
Cocos2d-x Support
If you use Cocos2d-x to develop your app, we provide another convenient solution for integration with TGSDK in Cocos2d-x projects with support for JavaScript and Lua. Please refer to
2、Initialize TGSDK
After registering an account and creating your App on Yomob Official Website you will acquire the corresponding product AppID
from the website, and then use this parameter to initialize TGSDK.
Note: If you are not extending TGSDK Activity and use yours, please don't forget to call the method with same name of TGSDK in the callback method of Activity during its life cycle.
If you need to launch your App in mainland China within different Chinese Android App Stores, please follow the steps of 《Launch on Chinese Android Channels》 for initialization.
class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TGSDK.initialize(
this,
"Your application ID from yomob",
null);
}
@Override
protected void onStart() {
super.onStart();
TGSDK.onStart(this);
}
@Override
protected void onStop() {
super.onStop();
TGSDK.onStop(this);
}
@Override
protected void onPause() {
super.onPause();
TGSDK.onPause(this);
}
@Override
protected void onResume() {
super.onResume();
TGSDK.onResume(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
TGSDK.onDestroy(this);
}
@Override
protected void onActivityResult(int reqCode, int resCode, Intent data) {
super.onActivityResult(reqCode, resCode, data);
TGSDK.onActivityResult(this, reqCode, resCode, data);
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
TGSDK.onRequestPermissionsResult(this, requestCode, permissions, grantResults);
}
}
3、Preload Ads Resources
To have enough time to load ads resources, it is recommended to call the preload API to load ads as early as possible. You can even call the preload API to load ads as soon as you initialize TGSDK.
TGSDK.preloadAd();
Note: The package name must match with the one you have registered under the App config in YoMob. Or else, you might not be able to load and play the ads
4、Play Ads
First, please create ad scenes for the registered App via Yomob Official Website. After acquiring the corresponding ad scene ID, you can use it to verify whether the ads are ready. If the ads of the corresponding scene are ready, the video ads play API can be called to play the ads.
if (TGSDK.couldShowAd("Your scene ID from yomob")) {
TGSDK.showAd(activity, "Your scene ID from yomob");
}
5. Broadcast of Banner type ads
For the specificity of Banner ads, you need to set the type and location of Banner ads in advance:
TGSDK.setBannerConfig(String scene, TGBannerType type,
int x, int y,
int width, int height,
int interval);
Parameter explanation:
-
scene
Banner ad corresponds to the registered ad scene ID -
type
Banner ad size type, whereTGBannerType
is divided into three types:
Banner Type | Banner Size |
---|---|
TGBannerNormal | 320*50 |
TGBannerLarge | 320*90 |
TGBannerMediumRectangle | 300*250 |
-
x, y
Banner The X coordinate and Y coordinate of the position where the position is placed, in px -
width, height
Banner The width and height of the ad reserved placement, in px -
interval
Banner The interval between ad rotations to switch ad content, in seconds
The coordinates are zero in the upper left corner of the screen, and the interval is the carousel time in seconds. It is recommended to be in the range of 30-120. Show Banner ads:
If (TGSDK.couldShowAd("Your scene ID from yomob")) {
TGSDK.showAd(activity, "Your scene ID from yomob");
}
You can also turn off Banner ads when needed:
TGSDK.closeBanner(Activity activity, "Your scene ID from yomob")
[Note] When you don't need to display the Banner ad or the view that displays the Banner ad is turned off, please call the
TGSDK.closeBanner(activity, scene)
method to manually close the Banner ad, otherwise it will affect the next time. Banner ads are displayed normally.
6、Advanced Usage
Enable Debug mode
After enabling Debug mode, extra debug information is reported to the logs. This is convenient for locating problems.
Note: Do not use Debug mode under a production environment. In addition, if it is necessary to enable Debug mode, set Debug mode enabled before calling the initialization API.
TGSDK.setDebugModel(true);
Set monitoring on ads preload event
You can monitor the ads loading process via listener
.
TGSDK.preloadAd(new ITGPreloadListener() {
@Override
public void onPreloadSuccess(String result) {
// Ads preload calling succeeds
}
@Override
public void onPreloadFailed(String scene, String error) {
// Ads preload calling fails
}
@Override
public void onAwardVideoLoaded(String result) {
//RewardVideo are ready
}
@Override
public void onInterstitialLoaded(String result) {
//Interstitial are ready
}
@Override
public void onInterstitialVideoLoaded(String result) {
//InterstitialVideo are ready
}
});
Set monitoring on ads playing behavior event
Monitor events occurred during ads playing process via listener
.
TGSDK.setADListener(new ITGADListener() {
@Override
public void onShowSuccess(String scene, String result) {
//Ads start to play(sceneid, Advertiser name)
}
@Override
public void onShowFailed(String scene, String result, String error) {
//Ads fail to play(sceneid, Advertiser name)
}
@Override
public void onADClick(String scene, String result) {
//After a user clicks ads, the ads playing page skips to other pages.(sceneid, Advertiser name)
}
@Override
public void onADClose(String scene, String result, boolean couldReward) {
//Ads are closed(sceneid, Advertiser name, couldReward)
}
});
[Note] BannerAd
onShowFailed
After the callback, the Banner ad fails to load, the ad does not display properly, you need to manually callTGSDK.closeBanner
to close the currently displayed Banner, and then try to callTGSDK.showAd
again to re-display the Banner ad.
Ads Test Tool
This functionality is only available in TGSDK with version 1.6.5 or above,we recommend you to upgrade your TGSDK for a better experience
Please do not use this function in a production environment. It is only for testing
During the testing phase, you can use APIs provided by Ads Test Tool instead of original ads API to better test your in App ads view logic.
Use Ads Test Tool API
TGSDK.showTestView(activity, "Your scene id from Yomob");
Instead of using the original API
TGSDK.showAd(activity, "Your scene id from Yomob");
The below UI will popup,you can test the Ads plugins included by test watching the available ads provided by these Ads networks included.

Report users ads watching behavior
To better analyze users ads watching behaviors, optimize ads viewing experience, and improve ads revenues of the products, we recommend that the data of the ads watching behaviors can be reported actively via related APIs to enhance users’ ads viewing experience
Report ads presentation behavior

As shown in the figure above, if the user has noticed that the product will have ads playing behavior via product UI or the product presents the controls that can be used by the user to choose whether to play the ads or not via UI, the corresponding behavior should be reported to TGSDK. For example, the product shown in the figure above presents the ads playing button, then the user can choose whether to play the ads in order to acquire bonus. At this time, this behavior should be reported to TGSDK.
TGSDK.showAdScene("Your scene ID from yomob");
Report ads watching rejection behavior of users

As shown in the figure above, if the user has noticed that the product will have ads playing behavior, and then the user rejects or gives up on playing the ads, the corresponding behavior can be reported to TGSDK at this time. For example, the user views the ads playing button UI and knows that the bonus can be acquired via watching an ads, but the user gives up. At this time, this behavior should be reported to the TGSDK.
TGSDK.reportAdRejected("Your scene ID from yomob");
Launch on Chinese Android Channels
Chinese Android App Stores are very complicated. If you need to launch your App on Chinese Android App Stores, you should pass specific ChannelId
during your initialization step. The ChannelId
can be found on YoMob App Setting or Chinese Android Channel List
class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TGSDK.initialize(
this,
"Your application ID from yomob",
"Your channel ID of App Store",
null);
}
@Override
protected void onStart() {
super.onStart();
TGSDK.onStart(this);
}
@Override
protected void onStop() {
super.onStop();
TGSDK.onStop(this);
}
@Override
protected void onPause() {
super.onPause();
TGSDK.onPause(this);
}
@Override
protected void onResume() {
super.onResume();
TGSDK.onResume(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
TGSDK.onDestroy(this);
}
@Override
protected void onActivityResult(int reqCode, int resCode, Intent data) {
super.onActivityResult(reqCode, resCode, data);
TGSDK.onActivityResult(this, reqCode, resCode, data);
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
TGSDK.onRequestPermissionsResult(this, requestCode, permissions, grantResults);
}
}
In order to make the initialization step easier when generating different APK for different Chinese Android App Stores, we support initialization from AndroidManifest.xml
file to get AppID and ChannelID. You need to add the below two settings in the AndroidManifest.xml
file of your project.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.soulgame.tgsdksampleapp.android">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<!-- Initialize TGSDK -->
<meta-data android:name="TGSDK_APPID" android:value="Your application id from Yomob" />
<meta-data android:name="TGSDK_CHANNELID" android:value="Your channel id of app store" />
<activity
android:name=".MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Once you have set AppID and ChannelID in your AndroidManifest.xml
file, then you don't need to pass in both two parameters during TGSDK initialization phase.
class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TGSDK.initialize(
this,
null);
}
@Override
protected void onStart() {
super.onStart();
TGSDK.onStart(this);
}
@Override
protected void onStop() {
super.onStop();
TGSDK.onStop(this);
}
@Override
protected void onPause() {
super.onPause();
TGSDK.onPause(this);
}
@Override
protected void onResume() {
super.onResume();
TGSDK.onResume(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
TGSDK.onDestroy(this);
}
@Override
protected void onActivityResult(int reqCode, int resCode, Intent data) {
super.onActivityResult(reqCode, resCode, data);
TGSDK.onActivityResult(this, reqCode, resCode, data);
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
TGSDK.onRequestPermissionsResult(this, requestCode, permissions, grantResults);
}
}
Chinese Android App Store Channels
Channel ID Name 10000 Official Web 10010 360 Mobile Assistant 10040 Myapp 10009 Xiaomi App Store 10041 Baidu Mobile Assistant 10029 Huawei App Stpre 10042 HiMarket 10024 Vivo 10035 GooglePlay 10023 Oppo Store 10037 Wandoujia 10017 Anzhi Market 10043 Meizu App Store 10004 91 Mobile Assistant 10034 China Unicom Wostore 10012 Lenovo Store
10026 Coolpad Store
10028 Sogou Mobile Assistant 10044 Gionee Anzhuoapk
10032 China Telecom Tianyi Store 10033 China Mobile Store 10001 Kuaiyong Sotre: 10003 PP Assistant 10002 Tongbutui 10005 iToos 10008 Yiwan 10011 Muzhiwan 10013 Kingsoft App Store 10015 Haima 10016 Dangle 10018 UC Web Store 10030 Youku 10038 Zhuoyi Market 10045 Mobile QQ 10046 Wechat Game 10047 Tencent Mobile Game 10048 4399 Game 10049 Letv Game 10050 Tiantian Game 10021 Yingyonghui 10051 Sina Game 10052 Netease Game 10053 Taptap 10054 Kuan 10055 CCPlay 10056 Pengyouwan 10057 Youpinwei