# Preparation before integration (java) *** Before integrating, please make sure you have downloaded the latest version of SuperSDK4.0+Demo (Java version)](http://www.supersdk.cn/download.html)。 ## Import libs library files Copy all aar packages downloaded from the basic module to the libs directory of the game project. If not, please create a new one. Then write the following code in build.gradle: ```java bcore-release.aar 基础库,必须导入,以下库均依赖此库,内含统计sdk,和工具基础库utils.jar supersdk-release.aar supersdk对外库,内含平台模块(platform),及对外接口 supersdk-mubao-release.aar supersdk母包,模拟渠道运行环境,供测试使用,打渠道包时可以删除 ``` ![Screenshot](img/java/android-studio-build.png) ```java 复制代码: repositories { flatDir{dirs'libs'} } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile(name:'bcore-release', ext:'aar') compile(name:'supersdk-mubao-release', ext:'aar') compile(name:'supersdk-release', ext:'aar') } ``` **Once you've written it, click the sync in the top right corner of the editing interface, the ‘Sync Now’ button. Synchronize this edit to the game project** ## Modify AndroidManifest (required) Add android:name="com.supersdk.openapi.SuperSdkApplication" to the application node. ```java ...... ``` ##Add an orginal package configuration file## Download the orginal package configuration from the packaging tool and add (replace) to the assets directory, as shown below ![Screenshot](img/java/java-mubao.png) ## initialization Interface description: Initialize supersdk and each module Interface invoke: The game must be invoked synchronously in the onCreate method of the activity. The game must be paused while invoking. Receiving successful callback from the platform module can be considered successful and the game can be resumed. ```java SuperSDK.init(MainActivity.this, mSuperSDKListener); ``` Interface callback: ```java private OnSuperSDKListener mSuperSDKListener = new OnSuperSDKListener() { @Override public void onSuperSDK(String moduleName, String funcName, String result) { //调用接口异步监听结果。 Log.d(TAG, "moduleName:" + moduleName + "\nfuncName:" + funcName + "\nresult:" + result); //判断这是平台模块("platform")内的方法,并且方法为初始化("init") if(BCoreConst.platform.MODULE_NAME.equals(moduleName) && BCoreConst.platform.FUNC_INIT.equals(funcName)) { //初始化回调,建议调用独立的初始化处理方法 init(result); }else { Log.d("supersdk", "其他模块方法的监听结果"); } } }; ``` ```java //这个方法处理初始化结果 privite void init(String result) { JSONObject json = JsonUtils.parseObject(result); int code = json.getIntValue("code"); if(code == BCoreCode.SUCCESS) { //初始化成功,游戏恢复,游戏继续运行 Log.d("supersdk", "初始化成功"); } else { //初始化失败,游戏必须重启,或弹框提示玩家重启 String msg = json.getString("msg"); Log.d("supersdk", "初始化失败,请重启游戏:"+code+", "+msg); } } ``` Log printing: ```java moduleName:platform funcName:init result:{"code":1,"msg":"没有更新接口"} ``` ## Integrated lifecycle interface Interface description: The lifecycle interface must be invoked synchronously in the corresponding method of the game's main activity. ```java @Override protected void onStart() { super.onStart(); SuperSDK.lifecycle.onStart(); } protected void onResume() { super.onResume(); SuperSDK.lifecycle.onResume(); }; @Override protected void onPause() { super.onPause(); SuperSDK.lifecycle.onPause(); } @Override protected void onStop() { super.onStop(); SuperSDK.lifecycle.onStop(); } @Override protected void onRestart() { super.onRestart(); SuperSDK.lifecycle.onRestart(); } @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); SuperSDK.lifecycle.onNewIntent(intent); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); SuperSDK.lifecycle.onActivityResult(requestCode, resultCode, data); } @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); SuperSDK.lifecycle.onSaveInstanceState(outState); } @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); SuperSDK.lifecycle.onConfigurationChanged(newConfig); } @Override protected void onDestroy() { super.onDestroy(); SuperSDK.lifecycle.onDestroy(); } ``` # Appendix In the invoke method, in order to let game developers do not have to remember to remember various string constant values, such as module name, method name and so on. Supersdk provides a constant class that records various module names and method name constant values. As shown below: | **String constant** | **Actual string** | **Description** | | --------------------------------------------- | ------------------- | ---------------------------------------------------- | | **Platform module constant** | | | | **BCoreConst.platform.MODULE_NAME** | **platform** | **Module name, fixed per module constant name** | | BCoreConst.platform.FUNC_LOGIN | login | log in | | BCoreConst.platform.FUNC_HAS_LOGOUT | hasLogout | Whether the channel has a logout interface | | BCoreConst.platform.FUNC_LOGOUT | logout | Logout | | BCoreConst.platform.FUNC_PAY | pay | Pay | | BCoreConst.platform.FUNC_EXIT | exit | exit the game | | BCoreConst.platform.FUNC_ENTER_GAME | enterGame | enter the game | | BCoreConst.platform.FUNC_CREATE_ROLE | createRole | Creating a Role | | BCoreConst.platform.FUNC_LEVEL_UP | levelUp | Role levelup | | BCoreConst.platform.FUNC_HAS_FORUM | hasForum | Determine if there is a forum | | BCoreConst.platform.FUNC_OPEN_FORUM | openForum | Open forum | | BCoreConst.platform.FUNC_HAS_USER_CENTER | hasUserCenter | Determine if there is a user center | | BCoreConst.platform.FUNC_OPEN_USER_CENTER | openUserCenter | Open the user center | | BCoreConst.platform.FUNC_HAS_CUSOMER_SERVICE | hasCustomerService | Determine if there is customer service | | BCoreConst.platform.FUNC_OPEN_CUSOMER_SERVICE | openCustomerService | Open customer service | | BCoreConst.platform.FUNC_OPEN_LOGIN_PAGE | openLoginPage | open login page | | BCoreConst.platform.FUNC_OPEN_HOME_PAGE | openHomePage | open homepage | | BCoreConst.platform.FUNC_HAS_GUEST | hasGuest | Whether the user is a guest | | BCoreConst.platform.FUNC_GUEST_UPGRADE | guestUpgrade | guest upgrade | | BCoreConst.platform.FUNC_OTHER_FUNCTION | otherFunction | Extension interface other | | BCoreConst.platform.FUNC_REPORT | report | Supersdk adds custom event tracking | | **Statistical module constant** | | | | **BCoreConst.stats.MODULE_NAME** | **stats** | **Module name** | | BCoreConst.stats.FUNC_REPORT | report | Statistical reporting | | BCoreConst.stats.FUNC_GET_DEVICE_INFO | getDeviceInfo | Get the device information | | **Tool module constant** | | | | **BCoreConst.tools.MODULE_NAME** | **tools** | **Module name** | | BCoreConst.tools.FUNC_GET_DEVICE_ID | getDeviceId | Get device ID | | BCoreConst.tools.FUNC_GET_COLLECTION_DATA | getCollectionData | Collecting device data | | BCoreConst.tools.FUNC_GET_IPINFO | getClientIPInfo | Obtain client IP information, such as ip area | | BCoreConst.tools.FUNC_GET_LANGUAGE | getLanguage | Get the local system language | | BCoreConst.tools.FUNC_GET_COUNTRY | getCountry | Get local country regions | | BCoreConst.tools.FUNC_COPY_TOCLIPBOARD | copyToClipboard | Copy text to clipboard | | BCoreConst.tools.FUNC_ALERT | alert | alert | | BCoreConst.tools.FUNC_GET_PACKAGE_NAME | getPackageName | Get the application package name | | BCoreConst.tools.FUNC_GET_VERSION_NAME | getVersionName | Get the versionName under AndroidManifest | | BCoreConst.tools.FUNC_GET_VERSION_CODE | getVersionCode | Get the versionCode under AndroidManifest | | BCoreConst.tools.FUNC_GET_META_DATA | getMetaData | Get the value of the meta-data under AndroidManifest | | BCoreConst.tools.FUNC_SET_SCREEN_LIGHT | setScreenLight | Adjust screen light | | BCoreConst.tools.FUNC_SAVE_DATA | saveData | save data | | BCoreConst.tools.FUNC_GET_DATA | getData | Get saved data | | **Configuration module constant** | | | | **BCoreConst.config.MODULE_NAME** | **config** | **Module name** | | BCoreConst.config.FUNC_GET_VALUE | getValue | 获取配置信息,如yz_game_id、extend、extend2等 | | **Advertising module constant** | | | | **BCoreConst.advert.MODULE_NAME** | **advert** | **Module name** | | BCoreConst.advert.FUNC_TRACK | track | Activate ad | | **Youzu module constant** | | | | **BCoreConst.advert.MODULE_NAME** | **youzu** | **Module name** | | BCoreConst.advert.FUNC_GET_VALUE | getValue | Get configuration, such as opid, opgameid |