Android SDK User Guide
version
Current version 1.5.1
1.Preparation Stage
1.1 We will provide
params | type | description |
---|---|---|
appSecret | string | Assigned Games secret |
u8sdk3.aar | file | Docking resources |
2.SDK Quick access
2.1 Development environment
1.com.android.tools.build:gradle version 3.2.1 or higher, build.gradle needs to add the following dependencies.
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation "com.android.support:support-v4:28.0.0"
implementation "com.android.support:cardview-v7:28.0.0"
implementation "com.android.support:recyclerview-v7:28.0.0"
implementation "android.arch.lifecycle:extensions:1.1.1"
implementation "pl.droidsonroids.gif:android-gif-drawable:1.2.18"
}
2.Add dependent libraries.
- Please copy u8sdk3.aar to the libs folder of the game project. If you are using Android Studio, you need to add dependency config in your build.gradle file.
2.2 Custom Application
1:If the game has no custom application class, you can just config the android:name attribute on the application node in AndroidManifest.xml to "com.u8.sdk.U8Application".
<application
android:name="com.u8.sdk.U8Application"
··· >
···
</application>
2:If the game has its own Application, you can check out our custom Application.
- 1).In the game's AndroidManifest.xml, set the android:name attribute of the application node to com.u8.sdk.U8Application.
- 2).If the game has its own application requirements or needs to do some operations in the application lifecycle method. So you can implement the interface in IApplicationListener.
- 3).The game's Application is defined above. Subsequently, in AndroidManifest.xml, configure the GameProxyApplication we defined above into meta-data, with Android:name U8_Game_Application.
For example, we define a GameProxyApplication to implement the IApplicationListener interface:
<application
···
android:name="com.u8.sdk.U8Application" >
<meta-data android:name="U8_Game_Application" android:value="com.u8.sdk.test.GameProxyApplication" />
···
</application>
2.3 Init Method
Tip : All interface calls are made through the com.u8.sdk.platform.U8Platform singleton.You should call this API in the onCreate function of the main activity of the game.
U8Platform.getInstance().init(this, new U8InitListener() {
@Override
public void onSwitchAccount(UToken data) {
//Switch to a callback for a new account through the SDK in the game. If the game receives the callback, it needs to guide the user to log in again and reload the corresponding character data for the new user
//switch login success
//Obtaining User Information from UToken
//UToken params:
//userID : Unique user ID generated by U8Server,
//sdkUserID : Channel SDK Platform User Unique ID,The game server needs to bind the game account ID with this sdkUserID
}
@Override
public void onPayResult(int code, String msg) {
Log.d("U8SDK", "pay result. code:"+code+";msg:"+msg);
switch(code){
case U8Code.CODE_PAY_SUCCESS:
//pay success
break;
case U8Code.CODE_PAY_FAIL:
//pay fail
break;
case U8Code.CODE_PAY_CANCEL:
//pay cancel
break;
case U8Code.CODE_PAY_UNKNOWN:
//pay unknown
break;
}
}
@Override
public void onLogout() {
}
@Override
public void onLoginResult(int code, UToken data) {
switch(code){
case U8Code.CODE_LOGIN_SUCCESS:
//login success
//enter game
//Obtaining User Information from UToken
//UToken params:
//userID : Unique user ID generated by U8Server,
//sdkUserID : Channel SDK Platform User Unique ID,The game server needs to bind the game account ID with this sdkUserID
break;
case U8Code.CODE_LOGIN_FAIL:
//login fail
break;
}
}
@Override
public void onInitResult(int code, String msg) {
Log.d("U8SDK", "init result.code:"+code+";msg:"+msg);
switch(code){
case U8Code.CODE_INIT_SUCCESS:
//init successs
break;
case U8Code.CODE_INIT_FAIL:
//init fail
break;
}
}
@Override
public void onShareResult(int code, String msg) {
Log.d("U8SDK", "share result.code:"+code+";msg:"+msg);
switch(code){
case U8Code.CODE_SHARE_SUCCESS:
//share success
break;
case U8Code.CODE_SHARE_FAILED:
//share fail
break;
}
}
@Override
public void onBindAccountResult(int code, String s) {
switch(code){
case U8Code.CODE_BIND_SUCCESS:
Log.d("U8SDK", "onBindAccountResult.code:"+code+";msg:bind success");
break;
}
}
@Override
public void onRealNameResult(int code, int idCardState) {
switch(code){
case U8Code.CODE_REALNAME_SUCCESS:
Log.d("U8SDK", "onRealNameResult:"+code+";msg:verify success");
break;
}
}
@Override
public void onProductQueryResult(List<ProductQueryResult> result) {
}
});
2.4 Life cycle of Activity
You should invoke all the life-cycle methods in the main activity of the game.
public void onActivityResult(int requestCode, int resultCode, Intent data){
U8SDK.getInstance().onActivityResult(requestCode, resultCode, data);
super.onActivityResult(requestCode, resultCode, data);
}
public void onStart(){
U8SDK.getInstance().onStart();
super.onStart();
}
public void onPause(){
U8SDK.getInstance().onPause();
super.onPause();
}
public void onResume(){
U8SDK.getInstance().onResume();
super.onResume();
}
public void onNewIntent(Intent newIntent){
U8SDK.getInstance().onNewIntent(newIntent);
super.onNewIntent(newIntent);
}
public void onStop(){
U8SDK.getInstance().onStop();
super.onStop();
}
public void onDestroy(){
U8SDK.getInstance().onDestroy();
super.onDestroy();
}
public void onRestart(){
U8SDK.getInstance().onRestart();
super.onRestart();
}
public void onConfigurationChanged(Configuration newConfig){
super.onConfigurationChanged(newConfig);
}
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults){
U8SDK.getInstance().onRequestPermissionResult(requestCode, permissions, grantResults);
}
2.5 Login
login(Activity activity)
- This method should be invoked immeditaly before user entering game, maybe caused on a login UI. You may design a login window with an login button and some other information on it. And you can call the login method when the user click on the login button. After the method called, a login dialog will be displayed on top of the window.
When user login with an exist account from SDK or register a new account from SDK, onLoginResult callback function in the U8InitListener will be called.
Example:
U8Platform.getInstance().login(activity);
2.6 Exit game
exitSDK(final U8ExitListener u8ExitListener)
- This method should be invoked at all of position where to exit the game. For example, when user click on a "exit" button in the game or the system back button, if the game logic is to let user exit, you should not kill the game process directly, but to call the exitSDK method of U8SDK instead.
This method has an callback interface named U8ExitListener. When the special SDK has no exit dialog, onGameExit function will be invoked. So you can show your own exit confirm dialog in the onGameExit callback function.
Example:
U8Platform.getInstance().exitSDK(new U8ExitListener() {
@Override
public void onGameExit() {
//Here you can show your own exit dialog.
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Confirm To Exit");
builder.setMessage("Are you sure to exit?");
builder.setCancelable(true);
builder.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
MainActivity.this.finish();
System.exit(0);
}
});
builder.setNeutralButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
//user cancel exit, just igore
}
});
builder.show();
}
});
2.7 Submit game data.
Note : Called after successful login; The parameter value cannot be passed null
submitExtraData(UserExtraData extraData)
- Some game stores need game developers to submit some data of the player for statistical use. This method should be called four times in different situation, including enter server, create new role, level up and exit game.
Parameter Description:
- extraData : role info
About the UserExtraData Object:
params | type | description |
---|---|---|
dataType | int | situation const enum. you can use the const properties in UserExtraData |
serverID | String | current game server id of the player |
serverName | String | current game server name of the player |
roleID | String | current role id of the player |
roleName | String | current role name of the player |
roleLevel | String | current level of the player |
moneyNum | String | the coin num of the player in the game |
roleCreateTime | long | the create time of the role in seconds. |
roleLevelUpTime | long | the last time when level up in seconds. |
vip | String | the vip level of the player |
UserExtraData dataType types:
- public static final int TYPE_SELECT_SERVER = 1; //select server
- public static final int TYPE_CREATE_ROLE = 2; //create new role.
- public static final int TYPE_ENTER_GAME = 3; //enter game
- public static final int TYPE_LEVEL_UP = 4; //level up
- public static final int TYPE_EXIT_GAME = 5; //exit game
Example:
UserExtraData data = new UserExtraData();
data.setDataType(UserExtraData.TYPE_CREATE_ROLE);
data.setMoneyNum(100);
data.setRoleCreateTime(System.currentTimeMillis()/1000);
data.setRoleID("role_100");
data.setRoleName("test_112");
data.setRoleLevel("10");
data.setRoleLevelUpTime(System.currentTimeMillis()/1000);
data.setServerID(10);
data.setServerName("server_10");
U8Platform.getInstance().submitExtraData(data);
2.8 Payment
pay(Activity context, PayParams payParams)
Interface Description:
- Recharge interface, open the SDK recharge interface. Successful or failed recharge will trigger the onPayResult interface in the initialization listener.
Parameter Description:
- context : android context
- payParams : The transfer object of payment parameters
about PayParams object:
params | type | description |
---|---|---|
productId | String | The unique id of the product |
productName | String | the name of the product. this will display on the payment dialog |
productDesc | String | detail description of the product |
price | double | Total Price , Currency is CNY |
buyNum | int | Fixed value : 1 |
coinNum | int | The coin num of the player in the game |
serverId | String | the unique id of the game server where the player in |
serverName | String | the name of the game server where the player in |
roleID | String | the unique id of the player in the game |
roleName | String | the name of the player in the game |
roleLevel | String | the level of the player in the game |
vip | String | the vip of the player in the game |
notifyUrl | String | The callback url for our server to notify when the user pay successfully |
extension | String | customized parameter,will be sent to game server with the pay result in the same way |
Example:
PayParams params = new PayParams();
params.setBuyNum(1);
params.setCoinNum(100);
params.setExtension(System.currentTimeMillis()+"");
params.setPrice(1);
params.setProductId("1");
params.setProductName("productName");
params.setProductDesc("productDesc");
params.setRoleId("1");
params.setRoleLevel(1);
params.setRoleName("roleName");
params.setServerId("10");
params.setServerName("serverName");
params.setVip("1");
params.setPayNotifyUrl("http://www.game.com/pay/callback");
U8Platform.getInstance().pay(this, params);
2.9 RewardVideo ad
gameRewardVideoAd(Activity context, RewardVideoAdInfo rewardVideoAdInfo,RewardVideoAdListener rewardVideoAdListener)
Interface Description:
- Motivating video advertising interface to pull up channels for motivating video advertising
Parameter Description:
- context : android context
- rewardVideoAdInfo : The transfer object of ad parameters
- rewardVideoAdListener : listener
About RewardVideoAdInfo object:
params | type | description |
---|---|---|
rewardVideoName | String | Name of reward |
rewardVideoAccount | String | Numer of reward |
mediaExtra | String | Video transmission parameters |
Extra | String | Transparent parameter |
Orientation | int | Playback direction.1:Vertical screen,2:Landscape screen |
Example:
RewardVideoAdInfo info = new RewardVideoAdInfo();
info.setRewardVideoName("Name of reward");
info.setRewardVideoAccount(1); //Numer of reward
info.setOrientation(1);//1:Vertical screen,2:Landscape screen
info.setUserId("111111111111");//user id
info.setMediaExtra("Video transmission parameters");//Video transmission parameters
info.setExtra("Transparent parameter");//Transparent parameter
U8Platform.getInstance().gameRewardVideoAd(MainActivity.this, info, new RewardVideoAdListener(){
@Override
public void onRequestADFail(int errorCode){
//request failure,errorCode
}
@Override
public void onRewardVideoAdComplete() {
//Video playback completed
}
@Override
public void onRewardVideoAdCancel() {
//Play Cancel
}
@Override
public void onRewardVideoAdClose(Boolean isNeedServerNotice) {
//Close the video interface
}
@Override
public void onRequestADSuccess() {
//Request successful
}
@Override
public void onRewardVideoAdSkipped() {
//skip
}
});
2.10 Game data event reporting interface
gameEvent(String eventId, Map<String Object> eventData)
Interface Description:
- Game data event reporting interface, trackingio reporting
Parameter Description:
- eventId : Event id,Provided by Operations
- eventData : Event data,Provided by Operations
Example:
Map<String, Object> eventData = new HashMap<String, Object>();
eventData.put("register", "register");
···
U8Platform.getInstance().gameEvent("mobile", eventData);
2.11 Thinkingdata reporting interface
submitTAUserInfo(int eventType,String eventID,JSONObject jsonObject)
Interface Description:
- Call the Thinkingdata reporting interface to report events and user attribute data
Parameter Description:
- eventType : Report type(0:Event reporting;1: User data reporting set;2: User data reporting setOnce;3: User data reporting add;4: Set public properties for events;6: Set up one-time event reporting;7: Set Updatable Event Reporting)
- eventID : Reported event name,Provided by Operations(User data reporting set,add,setOnce and Set public properties reporting can be null or '';Event reporting cannot be null or '')
- jsonObject : Report attribute data
Example:
U8Platform.getInstance().submitTAUserInfo(eventType, eventID, jsonObject);
Event transmission according to the documents provided by the operation
Role name modification
JSONObject jsonObject = new JSONObject();
jsonObject.put("mj_role_name","role_wx");
U8Platform.getInstance().submitTAUserInfo(1, "", jsonObject);
Logout of character
JSONObject jsonObject = new JSONObject();
U8Platform.getInstance().submitTAUserInfo(0, "mj_logout_role", jsonObject);
Report public attributes
JSONObject jsonObject = new JSONObject();
jsonObject.put("game_version","1.1.1");
U8Platform.getInstance().submitTAUserInfo(4, "", jsonObject);
3.Server-Side API
3.1 Login verification
1.1 Purpose
To prevent user information been tampered.
1.2 Steps
1) Once user logined, the OnLoginSuc callback function will be invoked. And you can get the information of the user from the UToken parameter which contains an unique id of the user, a temp token and some other fields.
2) Then the client connects to game server with these parameters.
3) Finally, the game server sends an http request to our server with these paramters to check whether the information is valid. If valid, you can let the user enter the server.
1.3 Server API
We use HTTP protocol to finish step 3
Http URL : https://api.sy.faxing.ledu.com/user/verifyAccount
Http Method : Post
Http Encoding: UTF-8
Http Parameters :
Name Description
userID userID in UToken when client login sucessfully
token token in UToken when client login successfully
sign sign = md5("userID="+userID+"token="+token+appSecret); appSecret is provided by us. sign is a md5 value(32 bit, lower)
Http Returns(json):
{
state: 1: success; 0: failed.
data: if state is 1, the data field will be provided
{
userID:unique id of the user in sdk
username:username of the user in sdk
channelID:channel id of the user in sdk
}
}
3.2 Payment callback
When U8Server receives a payment callback from the channel SDK and processes it successfully, we will call the payment callback address of the game server to notify the game server to ship the goods to the player. The callback address is passed in through the payNotifyURL field by the client when calling the payment interface. If the client does not transmit, it can be configured in the U8Server backend. Prioritize using client input.
Request address: The HTTP address where the game server receives the request, which is passed in when the client makes the payment.
Request method: POST
Parameter format: application/json
Request parameters (JSON format):
{
State: 1,//status, 1: successful; Other failures
data:{
ProductID: Product ID
OrderID: Order Number
UserID: User ID
ChannelID: Channel ID
GameID: Game ID
Server ID: Game Server ID
Money: Recharge amount, in cents per unit
Currency: Currency type, default RMB
Extension: Retrieve custom parameters from the order number server and return them as they are
SignType: Signature type, md5. This field does not participate in the signature process
Sign: Signature value. This field does not participate in the signature process
}
}
The game server returned:
The game server has processed successfully and will directly return a 'Success' string to U8Server. Failed, returns a 'FAIL' string.
Game server sign verification rules:
In the above data parameters, except for the signType and sign fields, all other fields are combined in alphabetical order in the following format:
signStr = "channelID=5¤cy=RMB&.....&userID=4344"
At the end of the combination string, add the AppSecret assigned by u8server for the game.
signStr += "&" + AppSecret
String localSign = md5(signStr)
if(localSign == sign) return true;
else return false;
Compare the locally generated md5 with the received sign. If they are consistent, the verification is passed.