Commit d495d19f8653fb161f5861daf64d63ecebe5409a
1 parent
5553a3ffd4
Exists in
master
upgrade to 4.9.0
Showing 3 changed files with 18 additions and 20 deletions Inline Diff
GameSDKDemo/build.gradle
1 | apply plugin: 'com.android.application' | 1 | apply plugin: 'com.android.application' |
2 | 2 | ||
3 | /*The config for internal testing,you could ignore it | 3 | /*The config for internal testing,you could ignore it |
4 | * gump内部测试使用,你可以自行配置,或者直接删除这部分内容 | 4 | * gump内部测试使用,你可以自行配置,或者直接删除这部分内容 |
5 | * --start-- | 5 | * --start-- |
6 | */ | 6 | */ |
7 | def keystorePSW = '' | 7 | def keystorePSW = '' |
8 | def keystoreAlias = '' | 8 | def keystoreAlias = '' |
9 | def keystoreAliasPSW = '' | 9 | def keystoreAliasPSW = '' |
10 | // default keystore file, PLZ config file path in local.properties | 10 | // default keystore file, PLZ config file path in local.properties |
11 | def keyfile = file('s.keystore.temp') | 11 | def keyfile = file('s.keystore.temp') |
12 | 12 | ||
13 | Properties properties = new Properties() | 13 | Properties properties = new Properties() |
14 | // local.properties file in the root director | 14 | // local.properties file in the root director |
15 | properties.load(project.file('local.properties').newDataInputStream()) | 15 | properties.load(project.file('local.properties').newDataInputStream()) |
16 | def keystoreFilepath = properties.getProperty("keystore.path") | 16 | def keystoreFilepath = properties.getProperty("keystore.path") |
17 | 17 | ||
18 | if (keystoreFilepath) { | 18 | if (keystoreFilepath) { |
19 | keystorePSW = properties.getProperty("keystore.password") | 19 | keystorePSW = properties.getProperty("keystore.password") |
20 | keystoreAlias = properties.getProperty("keystore.alias") | 20 | keystoreAlias = properties.getProperty("keystore.alias") |
21 | keystoreAliasPSW = properties.getProperty("keystore.key_passwd") | 21 | keystoreAliasPSW = properties.getProperty("keystore.key_passwd") |
22 | keyfile = file(keystoreFilepath) | 22 | keyfile = file(keystoreFilepath) |
23 | } | 23 | } |
24 | /* | 24 | /* |
25 | * The config for internal testing,you could ignore it | 25 | * The config for internal testing,you could ignore it |
26 | * gump内部测试使用,你可以自行配置,或者直接删除这部分内容 | 26 | * gump内部测试使用,你可以自行配置,或者直接删除这部分内容 |
27 | * --end-- | 27 | * --end-- |
28 | */ | 28 | */ |
29 | 29 | ||
30 | repositories { | 30 | repositories { |
31 | maven { | 31 | maven { |
32 | url "http://117.50.8.198:8081/nexus/content/repositories/sdk" | 32 | url "http://117.50.8.198:8081/nexus/content/repositories/sdk" |
33 | } | 33 | } |
34 | jcenter() | 34 | jcenter() |
35 | google() | 35 | google() |
36 | } | 36 | } |
37 | 37 | ||
38 | android { | 38 | android { |
39 | compileSdkVersion 28 | 39 | compileSdkVersion 30 |
40 | buildToolsVersion '28.0.3' | 40 | buildToolsVersion '28.0.3' |
41 | 41 | ||
42 | signingConfigs { | 42 | signingConfigs { |
43 | release { | 43 | release { |
44 | storeFile keyfile | 44 | storeFile keyfile |
45 | storePassword keystorePSW | 45 | storePassword keystorePSW |
46 | keyPassword keystoreAliasPSW | 46 | keyPassword keystoreAliasPSW |
47 | keyAlias keystoreAlias | 47 | keyAlias keystoreAlias |
48 | } | 48 | } |
49 | } | 49 | } |
50 | 50 | ||
51 | defaultConfig { | 51 | defaultConfig { |
52 | minSdkVersion 14 | 52 | minSdkVersion 14 |
53 | targetSdkVersion 27 | 53 | targetSdkVersion 30 |
54 | applicationId "mx.she.rd4" | 54 | applicationId "com.summon.empires2" |
55 | versionCode 6 | 55 | versionCode 38 |
56 | versionName "1.4" | 56 | versionName "1.0.3" |
57 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | 57 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" |
58 | signingConfig signingConfigs.release | 58 | signingConfig signingConfigs.release |
59 | } | 59 | } |
60 | buildTypes { | 60 | buildTypes { |
61 | release { | 61 | release { |
62 | minifyEnabled false | 62 | minifyEnabled false |
63 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | 63 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' |
64 | zipAlignEnabled true | 64 | zipAlignEnabled true |
65 | } | 65 | } |
66 | debug { | 66 | debug { |
67 | signingConfig signingConfigs.release | 67 | signingConfig signingConfigs.release |
68 | } | 68 | } |
69 | } | 69 | } |
70 | lintOptions { | 70 | lintOptions { |
71 | abortOnError false | 71 | abortOnError false |
72 | } | 72 | } |
73 | compileOptions { | 73 | compileOptions { |
74 | sourceCompatibility JavaVersion.VERSION_1_8 | 74 | sourceCompatibility JavaVersion.VERSION_1_8 |
75 | targetCompatibility JavaVersion.VERSION_1_8 | 75 | targetCompatibility JavaVersion.VERSION_1_8 |
76 | } | 76 | } |
77 | applicationVariants.all { | 77 | applicationVariants.all { |
78 | variant -> | 78 | variant -> |
79 | variant.outputs.all { | 79 | variant.outputs.all { |
80 | outputFileName = "GameSDKDemo-" + variant.name + defaultConfig.versionName + ".apk" | 80 | outputFileName = "GameSDKDemo-" + variant.name + defaultConfig.versionName + ".apk" |
81 | } | 81 | } |
82 | } | 82 | } |
83 | 83 | ||
84 | } | 84 | } |
85 | 85 | ||
86 | dependencies { | 86 | dependencies { |
87 | implementation fileTree(include: ['*.jar'], dir: 'libs') | 87 | implementation fileTree(include: ['*.jar'], dir: 'libs') |
88 | // implementation 'com.android.support:support-v4:27.1.1' | 88 | // implementation 'com.android.support:support-v4:27.1.1' |
89 | implementation 'androidx.appcompat:appcompat:1.1.0' | 89 | implementation 'androidx.appcompat:appcompat:1.2.0' |
90 | implementation 'androidx.fragment:fragment:1.1.0' | 90 | implementation 'androidx.fragment:fragment:1.2.5' |
91 | implementation 'com.google.android.material:material:1.0.0' | 91 | implementation 'com.google.android.material:material:1.2.1' |
92 | testImplementation 'junit:junit:4.12' | 92 | testImplementation 'junit:junit:4.12' |
93 | // implementation 'com.android.support:appcompat-v7:27.1.1' | 93 | // implementation 'com.android.support:appcompat-v7:27.1.1' |
94 | // implementation 'com.android.support:design:27.1.1' | 94 | // implementation 'com.android.support:design:27.1.1' |
95 | // implementation project(':GameSDK') | 95 | implementation project(':GameSDK') |
96 | // implementation project(':IAP5Helper') | 96 | // implementation project(':IAP5Helper') |
97 | implementation 'com.gumptech.sdk:GameSDK:4.8.0' | 97 | // implementation 'com.gumptech.sdk:GameSDK:4.8.0' |
98 | // implementation 'com.gump.game.sdk:SamsungIAP:5.1.1' | 98 | // implementation 'com.gump.game.sdk:SamsungIAP:5.1.1' |
99 | } | 99 | } |
100 | 100 |
GameSDKDemo/src/main/java/com/gump/game/sdk/demo/MainActivity.java
1 | package com.gump.game.sdk.demo; | 1 | package com.gump.game.sdk.demo; |
2 | 2 | ||
3 | import android.os.Bundle; | 3 | import android.os.Bundle; |
4 | import android.util.Log; | 4 | import android.util.Log; |
5 | import android.widget.Button; | 5 | import android.widget.Button; |
6 | import android.widget.TextView; | 6 | import android.widget.TextView; |
7 | import android.widget.Toast; | 7 | import android.widget.Toast; |
8 | 8 | ||
9 | import com.gump.game.sdk.GameSDK; | 9 | import com.gump.game.sdk.GameSDK; |
10 | import com.gump.game.sdk.GumpPreference; | 10 | import com.gump.game.sdk.GumpPreference; |
11 | import com.gump.game.sdk.SDKSettings; | 11 | import com.gump.game.sdk.SDKSettings; |
12 | import com.gump.game.sdk.bean.GumpUser; | 12 | import com.gump.game.sdk.bean.GumpUser; |
13 | import com.gump.game.sdk.callback.LoginStateListener; | 13 | import com.gump.game.sdk.callback.LoginStateListener; |
14 | import com.gump.game.sdk.callback.RechargeCallback; | 14 | import com.gump.game.sdk.callback.RechargeCallback; |
15 | import com.gump.game.sdk.passport.fb.FBAccessToken; | 15 | import com.gump.game.sdk.passport.fb.FBAccessToken; |
16 | 16 | ||
17 | import java.util.Locale; | 17 | import java.util.Locale; |
18 | 18 | ||
19 | import androidx.appcompat.app.AppCompatActivity; | 19 | import androidx.appcompat.app.AppCompatActivity; |
20 | 20 | ||
21 | public class MainActivity extends AppCompatActivity implements RechargeCallback { | 21 | public class MainActivity extends AppCompatActivity implements RechargeCallback { |
22 | 22 | ||
23 | private static final String TAG = "MainActivity"; | 23 | private static final String TAG = "MainActivity"; |
24 | 24 | ||
25 | private TextView tvVersion; | 25 | private TextView tvVersion; |
26 | private TextView userInfo; | 26 | private TextView userInfo; |
27 | 27 | ||
28 | private Button btnLoginOrLogout; | 28 | private Button btnLoginOrLogout; |
29 | private Button btnCheckState; | 29 | private Button btnCheckState; |
30 | private Button btnPay; | 30 | private Button btnPay; |
31 | private Button btnIap; | 31 | private Button btnIap; |
32 | 32 | ||
33 | private String appId = "100"; | 33 | private String appId = "10117"; |
34 | private String appKey = "f899139df5e1059396431415e770c6dd"; | 34 | private String channelId = "1030"; |
35 | private GumpUser gumpUser; | 35 | private GumpUser gumpUser; |
36 | 36 | ||
37 | /** | 37 | /** |
38 | * 测试数据 | 38 | * 测试数据 |
39 | */ | 39 | */ |
40 | String serverId = "100"; | 40 | String serverId = "S168"; |
41 | String roleId = "41080"; | 41 | String roleId = "168000089"; |
42 | 42 | ||
43 | 43 | ||
44 | @Override | 44 | @Override |
45 | protected void onCreate(Bundle savedInstanceState) { | 45 | protected void onCreate(Bundle savedInstanceState) { |
46 | super.onCreate(savedInstanceState); | 46 | super.onCreate(savedInstanceState); |
47 | setContentView(R.layout.activity_main); | 47 | setContentView(R.layout.activity_main); |
48 | 48 | ||
49 | tvVersion = findViewById(R.id.version); | 49 | tvVersion = findViewById(R.id.version); |
50 | userInfo = findViewById(R.id.user_info); | 50 | userInfo = findViewById(R.id.user_info); |
51 | btnLoginOrLogout = findViewById(R.id.login_or_logout); | 51 | btnLoginOrLogout = findViewById(R.id.login_or_logout); |
52 | btnCheckState = findViewById(R.id.check_state); | 52 | btnCheckState = findViewById(R.id.check_state); |
53 | btnLoginOrLogout.setOnClickListener(v -> { | 53 | btnLoginOrLogout.setOnClickListener(v -> { |
54 | if (btnLoginOrLogout.getTag() == null || (Integer) btnLoginOrLogout.getTag() == 0) | 54 | if (btnLoginOrLogout.getTag() == null || (Integer) btnLoginOrLogout.getTag() == 0) |
55 | GameSDK.login(MainActivity.this); | 55 | GameSDK.login(MainActivity.this); |
56 | else | 56 | else |
57 | GameSDK.logout(MainActivity.this); | 57 | GameSDK.logout(MainActivity.this); |
58 | }); | 58 | }); |
59 | btnCheckState.setOnClickListener(v -> { | 59 | btnCheckState.setOnClickListener(v -> { |
60 | GameSDK.iapUsable(MainActivity.this, serverId, roleId, usable -> { | 60 | GameSDK.iapUsable(MainActivity.this, serverId, roleId, usable -> { |
61 | btnIap.setEnabled(usable); | 61 | btnIap.setEnabled(usable); |
62 | btnPay.setEnabled(!usable); | 62 | btnPay.setEnabled(!usable); |
63 | }); | 63 | }); |
64 | }); | 64 | }); |
65 | btnPay = findViewById(R.id.pay); | 65 | btnPay = findViewById(R.id.pay); |
66 | btnPay.setOnClickListener(v -> { | 66 | btnPay.setOnClickListener(v -> { |
67 | PaymentInfoSubmitFragment submitFragment = PaymentInfoSubmitFragment.newInstance(payInfo -> GameSDK.pay(MainActivity.this, payInfo, MainActivity.this)); | 67 | PaymentInfoSubmitFragment submitFragment = PaymentInfoSubmitFragment.newInstance(payInfo -> GameSDK.pay(MainActivity.this, payInfo, MainActivity.this)); |
68 | submitFragment.show(getSupportFragmentManager(), "pay"); | 68 | submitFragment.show(getSupportFragmentManager(), "pay"); |
69 | }); | 69 | }); |
70 | btnIap = findViewById(R.id.iap); | 70 | btnIap = findViewById(R.id.iap); |
71 | btnIap.setOnClickListener(v -> { | 71 | btnIap.setOnClickListener(v -> { |
72 | PaymentInfoSubmitFragment submitFragment = PaymentInfoSubmitFragment.newInstance(payInfo -> GameSDK.iap(MainActivity.this, payInfo, MainActivity.this)); | 72 | PaymentInfoSubmitFragment submitFragment = PaymentInfoSubmitFragment.newInstance(payInfo -> GameSDK.iap(MainActivity.this, payInfo, MainActivity.this)); |
73 | submitFragment.show(getSupportFragmentManager(), "iap"); | 73 | submitFragment.show(getSupportFragmentManager(), "iap"); |
74 | }); | 74 | }); |
75 | 75 | ||
76 | 76 | ||
77 | Log.i("DEMO", "country:" + Locale.getDefault().getCountry() + ",language:" + Locale.getDefault().getLanguage()); | 77 | Log.i("DEMO", "country:" + Locale.getDefault().getCountry() + ",language:" + Locale.getDefault().getLanguage()); |
78 | 78 | ||
79 | GameSDK.getSettings().setDebug(false); | 79 | GameSDK.getSettings().setDebug(false); |
80 | /** | 80 | /** |
81 | * 设置是否打印debug日志 | 81 | * 设置是否打印debug日志 |
82 | */ | 82 | */ |
83 | GameSDK.getSettings().enableDebugLogging(true); | 83 | GameSDK.getSettings().enableDebugLogging(true); |
84 | /** | 84 | /** |
85 | * 设置启用facebook登录 | 85 | * 设置启用facebook登录 |
86 | */ | 86 | */ |
87 | GameSDK.getSettings().requestThirdSupport(SDKSettings.THIRD_SUPPORT_FB); | 87 | GameSDK.getSettings().requestThirdSupport(SDKSettings.THIRD_SUPPORT_FB); |
88 | 88 | ||
89 | /** | 89 | /** |
90 | * 设置启用google登录 | 90 | * 设置启用google登录 |
91 | */ | 91 | */ |
92 | GameSDK.getSettings().requestThirdSupport(SDKSettings.THIRD_SUPPORT_GOOGLE); | 92 | GameSDK.getSettings().requestThirdSupport(SDKSettings.THIRD_SUPPORT_GOOGLE); |
93 | 93 | ||
94 | /** | 94 | /** |
95 | * 设置启用Line登录 | 95 | * 设置启用Line登录 |
96 | */ | 96 | */ |
97 | GameSDK.getSettings().requestThirdSupport(SDKSettings.THIRD_SUPPORT_LINE); | 97 | GameSDK.getSettings().requestThirdSupport(SDKSettings.THIRD_SUPPORT_LINE); |
98 | 98 | ||
99 | 99 | ||
100 | /** | 100 | /** |
101 | * 设置用户登录状态监听器 | 101 | * 设置用户登录状态监听器 |
102 | */ | 102 | */ |
103 | 103 | ||
104 | GameSDK.setUserStateListener(new LoginStateListener() { | 104 | GameSDK.setUserStateListener(new LoginStateListener() { |
105 | @Override | 105 | @Override |
106 | public void onLoginSuccess(GumpUser user) { | 106 | public void onLoginSuccess(GumpUser user) { |
107 | btnCheckState.setEnabled(true); | 107 | btnCheckState.setEnabled(true); |
108 | gumpUser = user; | 108 | gumpUser = user; |
109 | String userType = null; | 109 | String userType = null; |
110 | switch (user.getAccountType()) { | 110 | switch (user.getAccountType()) { |
111 | case GumpPreference.ACCOUNT_TYPE_FB: | 111 | case GumpPreference.ACCOUNT_TYPE_FB: |
112 | userType = "Facebook登录"; | 112 | userType = "Facebook登录"; |
113 | String fbToken = FBAccessToken.getCurrentAccessToken().getToken(); | 113 | String fbToken = FBAccessToken.getCurrentAccessToken().getToken(); |
114 | Log.d(TAG, "FBAccessToken:" + fbToken); | 114 | Log.d(TAG, "FBAccessToken:" + fbToken); |
115 | break; | 115 | break; |
116 | case GumpPreference.ACCOUNT_TYPE_QUICK_REG: | 116 | case GumpPreference.ACCOUNT_TYPE_QUICK_REG: |
117 | userType = "快速登录"; | 117 | userType = "快速登录"; |
118 | break; | 118 | break; |
119 | case GumpPreference.ACCOUNT_TYPE_REG: | 119 | case GumpPreference.ACCOUNT_TYPE_REG: |
120 | userType = "gump注册用户"; | 120 | userType = "gump注册用户"; |
121 | break; | 121 | break; |
122 | case GumpPreference.ACCOUNT_TYPE_GOOGLE: | 122 | case GumpPreference.ACCOUNT_TYPE_GOOGLE: |
123 | userType = "google 登录"; | 123 | userType = "google 登录"; |
124 | break; | 124 | break; |
125 | case GumpPreference.ACCOUNT_TYPE_LINE: | 125 | case GumpPreference.ACCOUNT_TYPE_LINE: |
126 | userType = "Line登录"; | 126 | userType = "Line登录"; |
127 | break; | 127 | break; |
128 | } | 128 | } |
129 | userInfo.setText(" Userid:" + user.getUid() + "\n accountType:(" + user.getAccountType() + ") " + userType + "\n sessionKey:" + user.getSessionKey() | 129 | userInfo.setText(" Userid:" + user.getUid() + "\n accountType:(" + user.getAccountType() + ") " + userType + "\n sessionKey:" + user.getSessionKey() |
130 | .getToken()); | 130 | .getToken()); |
131 | btnLoginOrLogout.setText("Logout"); | 131 | btnLoginOrLogout.setText("Logout"); |
132 | btnLoginOrLogout.setTag(1); | 132 | btnLoginOrLogout.setTag(1); |
133 | } | 133 | } |
134 | 134 | ||
135 | @Override | 135 | @Override |
136 | public void onLoginFailed(int code, String msg) { | 136 | public void onLoginFailed(int code, String msg) { |
137 | userInfo.setText(msg); | 137 | userInfo.setText(msg); |
138 | Toast.makeText(MainActivity.this, "Login failed:code=" + code + ",message=" + msg, Toast.LENGTH_SHORT).show(); | 138 | Toast.makeText(MainActivity.this, "Login failed:code=" + code + ",message=" + msg, Toast.LENGTH_SHORT).show(); |
139 | } | 139 | } |
140 | 140 | ||
141 | @Override | 141 | @Override |
142 | public void onLoginCanceled() { | 142 | public void onLoginCanceled() { |
143 | Toast.makeText(MainActivity.this, "operate be canceled", Toast.LENGTH_SHORT).show(); | 143 | Toast.makeText(MainActivity.this, "operate be canceled", Toast.LENGTH_SHORT).show(); |
144 | } | 144 | } |
145 | 145 | ||
146 | @Override | 146 | @Override |
147 | public void onLogout() { | 147 | public void onLogout() { |
148 | btnLoginOrLogout.setText("Login"); | 148 | btnLoginOrLogout.setText("Login"); |
149 | btnLoginOrLogout.setTag(0); | 149 | btnLoginOrLogout.setTag(0); |
150 | userInfo.setText("User is logout"); | 150 | userInfo.setText("User is logout"); |
151 | } | 151 | } |
152 | 152 | ||
153 | @Override | 153 | @Override |
154 | public void onPermissionDenied(String[] deniedPermissions) { | 154 | public void onPermissionDenied(String[] deniedPermissions) { |
155 | StringBuilder sb = new StringBuilder(); | 155 | StringBuilder sb = new StringBuilder(); |
156 | for (String s : deniedPermissions) { | 156 | for (String s : deniedPermissions) { |
157 | sb.append(s); | 157 | sb.append(s); |
158 | sb.append(","); | 158 | sb.append(","); |
159 | } | 159 | } |
160 | Toast.makeText(MainActivity.this, "Permission denied:" + sb.toString(), Toast.LENGTH_SHORT).show(); | 160 | Toast.makeText(MainActivity.this, "Permission denied:" + sb.toString(), Toast.LENGTH_SHORT).show(); |
161 | } | 161 | } |
162 | }); | 162 | }); |
163 | /** | 163 | /** |
164 | * 初始化sdk | 164 | * 初始化sdk |
165 | */ | 165 | */ |
166 | GameSDK.init(getApplicationContext(), appId); | 166 | GameSDK.init(getApplicationContext(), appId,channelId); |
167 | 167 | ||
168 | tvVersion.setText("SDK Version:" + GameSDK.getVersion()); | 168 | tvVersion.setText("SDK Version:" + GameSDK.getVersion()); |
169 | 169 | ||
170 | } | 170 | } |
171 | 171 | ||
172 | private void checkRisk() { | 172 | private void checkRisk() { |
173 | GameSDK.inspectRiskLevel(this, isRisk -> Log.i(TAG, isRisk ? "There is some risks" : "Nothing is risk")); | 173 | GameSDK.inspectRiskLevel(this, isRisk -> Log.i(TAG, isRisk ? "There is some risks" : "Nothing is risk")); |
174 | } | 174 | } |
175 | 175 | ||
176 | @Override | 176 | @Override |
177 | public void onPurchaseCompleted() { | 177 | public void onPurchaseCompleted() { |
178 | Log.i(TAG, "purchase completed"); | 178 | Log.i(TAG, "purchase completed"); |
179 | } | 179 | } |
180 | 180 | ||
181 | @Override | 181 | @Override |
182 | public void onPurchaseError(int code, String msg) { | 182 | public void onPurchaseError(int code, String msg) { |
183 | Log.i(TAG, "purchase error:"+code+","+msg); | 183 | Log.i(TAG, "purchase error:"+code+","+msg); |
184 | } | 184 | } |
185 | 185 | ||
186 | @Override | 186 | @Override |
187 | public void onPurchaseCanceled() { | 187 | public void onPurchaseCanceled() { |
188 | Log.i(TAG, "purchase canceled"); | 188 | Log.i(TAG, "purchase canceled"); |
189 | } | 189 | } |
190 | 190 | ||
191 | 191 | ||
192 | } | 192 | } |
193 | 193 |
README.md
1 | # Gump SDK 4 for Android接入文档 | 1 | # Gump SDK 4 for Android接入文档 |
2 | 2 | ||
3 | V4.8.6 | 3 | V4.9.0 |
4 | 2020年08月6日 | 4 | 2021年06月21日 |
5 | 5 | ||
6 | 6 | ||
7 | ## 版本概述 | 7 | ## 版本概述 |
8 | 8 | ||
9 | 此版本为使用AndroidStudio开发的版本,使用aar的方式提供sdk接入包,并使用gradle在线依赖方式,aar内别不包含依赖包,请按此文档描述接入. | 9 | 此版本为使用AndroidStudio开发的版本,使用aar的方式提供sdk接入包,并使用gradle在线依赖方式,aar内别不包含依赖包,请按此文档描述接入. |
10 | 10 | ||
11 | 此SDK适用android4.0以上系统. | 11 | 此SDK适用android4.0以上系统. |
12 | 12 | ||
13 | ## 第一章 接入指南 | 13 | ## 第一章 接入指南 |
14 | ### 1.依赖导入 | 14 | ### 1.依赖导入 |
15 | 配置gradle,以下为必须项 | 15 | 配置gradle,以下为必须项 |
16 | 16 | ||
17 | ```groovy | 17 | ```groovy |
18 | repositories{ | 18 | repositories{ |
19 | maven{ | 19 | maven{ |
20 | url "http://117.50.8.198:8081/nexus/content/repositories/sdk" | 20 | url "http://117.50.8.198:8081/nexus/content/repositories/sdk" |
21 | } | 21 | } |
22 | } | 22 | } |
23 | dependencies { | 23 | dependencies { |
24 | implementation 'com.gumptech.sdk:GameSDK:4.8.6' | 24 | implementation 'com.gumptech.sdk:GameSDK:4.9.0' |
25 | 25 | ||
26 | } | 26 | } |
27 | ``` | 27 | ``` |
28 | 28 | ||
29 | 29 | ||
30 | ### 2.修改AndroidManifest.xml文件 | 30 | ### 2.修改AndroidManifest.xml文件 |
31 | 首先添加必要的权限,如下所示: | 31 | 首先添加必要的权限,如下所示: |
32 | 32 | ||
33 | ```xml | 33 | ```xml |
34 | <uses-permission android:name="android.permission.INTERNET" /> | 34 | <uses-permission android:name="android.permission.INTERNET" /> |
35 | <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> | 35 | <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> |
36 | <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> | 36 | <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> |
37 | <!-- VERY IMPORTANT! Don't forget this permission, or in-app billing won't work. --> | ||
38 | <uses-permission android:name="com.android.vending.BILLING" /> | ||
39 | ``` | 37 | ``` |
40 | 38 | ||
41 | 其次注册相应的Activity,具体如下: | 39 | 其次注册相应的Activity,具体如下: |
42 | 40 | ||
43 | ```xml | 41 | ```xml |
44 | <activity | 42 | <activity |
45 | android:name="com.gump.game.sdk.PassportActivity" | 43 | android:name="com.gump.game.sdk.PassportActivity" |
46 | android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout" | 44 | android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout" |
47 | android:launchMode="singleTask" | 45 | android:launchMode="singleTask" |
48 | android:theme="@style/Theme.Origin" //登录界面的主题,可选项:Theme.Origin\Theme.Orange\Theme.Blue\Theme.Pink | 46 | android:theme="@style/Theme.Origin" //登录界面的主题,可选项:Theme.Origin\Theme.Orange\Theme.Blue\Theme.Pink |
49 | android:screenOrientation="behind" | 47 | android:screenOrientation="behind" |
50 | android:windowSoftInputMode="stateAlwaysHidden|adjustPan"> | 48 | android:windowSoftInputMode="stateAlwaysHidden|adjustPan"> |
51 | </activity> | 49 | </activity> |
52 | <activity | 50 | <activity |
53 | android:name="com.gump.game.sdk.RechargeActivity" | 51 | android:name="com.gump.game.sdk.RechargeActivity" |
54 | android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout" | 52 | android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout" |
55 | android:launchMode="singleTask" | 53 | android:launchMode="singleTask" |
56 | android:screenOrientation="behind" | 54 | android:screenOrientation="behind" |
57 | android:theme="@style/Theme.Translucent" > | 55 | android:theme="@style/Theme.Translucent" > |
58 | <intent-filter> | 56 | <intent-filter> |
59 | <category android:name="android.intent.category.DEFAULT" /> | 57 | <category android:name="android.intent.category.DEFAULT" /> |
60 | <action android:name="android.intent.action.VIEW" /> | 58 | <action android:name="android.intent.action.VIEW" /> |
61 | <category android:name="android.intent.category.BROWSABLE" /> | 59 | <category android:name="android.intent.category.BROWSABLE" /> |
62 | <data | 60 | <data |
63 | android:host="com.gump.sdk" | 61 | android:host="com.gump.sdk" |
64 | android:scheme="gump+游戏的appId" /> | 62 | android:scheme="gump+游戏的appId" /> |
65 | </intent-filter> | 63 | </intent-filter> |
66 | </activity> | 64 | </activity> |
67 | ``` | 65 | ``` |
68 | 66 | ||
69 | ### 3.向Gump平台索要游戏ID(AppID),完成代码接入 | 67 | ### 3.向Gump平台索要游戏ID(AppID),完成代码接入 |
70 | 正式开始接入逻辑代码前,先介绍下一些附加设置,以方便代码接入 | 68 | 正式开始接入逻辑代码前,先介绍下一些附加设置,以方便代码接入 |
71 | 69 | ||
72 | *是否打印debug日志 | 70 | *是否打印debug日志 |
73 | 71 | ||
74 | ```java | 72 | ```java |
75 | GameSDK.getSettings().enableDebugLogging(true); | 73 | GameSDK.getSettings().enableDebugLogging(true); |
76 | ``` | 74 | ``` |
77 | 75 | ||
78 | *设置需要启用的第三方登录,参数可选类型见第二章:[第三方登录平台](http://repository.gumptech.com:81/document/gamesdk4-android/blob/master/IntegrationGuide.md#1-third_plat) 字段说明 | 76 | *设置需要启用的第三方登录,参数可选类型见第二章:[第三方登录平台](http://repository.gumptech.com:81/document/gamesdk4-android/blob/master/IntegrationGuide.md#1-third_plat) 字段说明 |
79 | 77 | ||
80 | ```java | 78 | ```java |
81 | GameSDK.getSettings().requestThirdSupport(SDKSettings.THIRD_SUPPORT_*); | 79 | GameSDK.getSettings().requestThirdSupport(SDKSettings.THIRD_SUPPORT_*); |
82 | ``` | 80 | ``` |
83 | 81 | ||
84 | 82 | ||
85 | #### 1.调用GameSDK前需要执行初始化。 | 83 | #### 1.调用GameSDK前需要执行初始化。 |
86 | 84 | ||
87 | 若不需要分渠道 | 85 | 若不需要分渠道 |
88 | 86 | ||
89 | ```java | 87 | ```java |
90 | GameSDK.init(Context,Appid); | 88 | GameSDK.init(Context,Appid); |
91 | ``` | 89 | ``` |
92 | 如果需要定义渠道,必须使用如下方法 | 90 | 如果需要定义渠道,必须使用如下方法 |
93 | 91 | ||
94 | ```java | 92 | ```java |
95 | GameSDK.init(Context,Appid,ChannelId); | 93 | GameSDK.init(Context,Appid,ChannelId); |
96 | ``` | 94 | ``` |
97 | 95 | ||
98 | 96 | ||
99 | #### 2.调用GameSDK的登录方法,将执行登录流程,需要一个Activity实例作参数 | 97 | #### 2.调用GameSDK的登录方法,将执行登录流程,需要一个Activity实例作参数 |
100 | 98 | ||
101 | ```java | 99 | ```java |
102 | GameSDK.login(Activity); | 100 | GameSDK.login(Activity); |
103 | ``` | 101 | ``` |
104 | 在此之前,开发者需要注册用户状态监听以接受用户的登录/登出通知,通常如下: | 102 | 在此之前,开发者需要注册用户状态监听以接受用户的登录/登出通知,通常如下: |
105 | 103 | ||
106 | ```java | 104 | ```java |
107 | GameSDK.setUserStateListener(new LoginStateListener() { | 105 | GameSDK.setUserStateListener(new LoginStateListener() { |
108 | @Override | 106 | @Override |
109 | public void onLoginSuccess(GumpUser gumpUser) { | 107 | public void onLoginSuccess(GumpUser gumpUser) { |
110 | //登录成功,用户信息包含在GumpUser对象里 | 108 | //登录成功,用户信息包含在GumpUser对象里 |
111 | } | 109 | } |
112 | 110 | ||
113 | @Override | 111 | @Override |
114 | public void onLoginFailed(int code, String msg) { | 112 | public void onLoginFailed(int code, String msg) { |
115 | //登录出错,根据错误码和信息判断错误类型 | 113 | //登录出错,根据错误码和信息判断错误类型 |
116 | Toast.makeText(MainActivity.this, "Login failed:code="+code+",message="+msg, Toast.LENGTH_SHORT).show(); | 114 | Toast.makeText(MainActivity.this, "Login failed:code="+code+",message="+msg, Toast.LENGTH_SHORT).show(); |
117 | } | 115 | } |
118 | 116 | ||
119 | @Override | 117 | @Override |
120 | public void onLoginCanceled() { | 118 | public void onLoginCanceled() { |
121 | //用户取消登录 | 119 | //用户取消登录 |
122 | Toast.makeText(MainActivity.this, "operate be canceled", Toast.LENGTH_SHORT).show(); | 120 | Toast.makeText(MainActivity.this, "operate be canceled", Toast.LENGTH_SHORT).show(); |
123 | } | 121 | } |
124 | 122 | ||
125 | @Override | 123 | @Override |
126 | public void onLogout() { | 124 | public void onLogout() { |
127 | //用户登出 | 125 | //用户登出 |
128 | 126 | ||
129 | } | 127 | } |
130 | @Override | 128 | @Override |
131 | public void onPermissionDenied(String[] deniedPermissions) { | 129 | public void onPermissionDenied(String[] deniedPermissions) { |
132 | //用户未授予权限,参数为没有获取的权限 | 130 | //用户未授予权限,参数为没有获取的权限 |
133 | } | 131 | } |
134 | }); | 132 | }); |
135 | ``` | 133 | ``` |
136 | 134 | ||
137 | 如上成功登录后收到的GumpUser对象包含以下信息 | 135 | 如上成功登录后收到的GumpUser对象包含以下信息 |
138 | 136 | ||
139 | ```java | 137 | ```java |
140 | gumpUser.getUid();//获取用户的userid,此Id标识唯一用户! | 138 | gumpUser.getUid();//获取用户的userid,此Id标识唯一用户! |
141 | gumpUser.getAccountType();//用户类型,此类型数据可从GumpPreference常量获取 | 139 | gumpUser.getAccountType();//用户类型,此类型数据可从GumpPreference常量获取 |
142 | gumpUser.getSessionKey();//登录的sessionKey对象,获取sessionKey字符串请使用此对象的getToken()方法 | 140 | gumpUser.getSessionKey();//登录的sessionKey对象,获取sessionKey字符串请使用此对象的getToken()方法 |
143 | ``` | 141 | ``` |
144 | 142 | ||
145 | #### 3.支付功能 | 143 | #### 3.支付功能 |
146 | 调用支付前需先判断支付状态,根据状态调用支付方法 | 144 | 调用支付前需先判断支付状态,根据状态调用支付方法 |
147 | 145 | ||
148 | ```java | 146 | ```java |
149 | GameSDK.iapUsable(Activity, serverId, roleId, new ResultCallback() { | 147 | GameSDK.iapUsable(Activity, serverId, roleId, new ResultCallback() { |
150 | @Override | 148 | @Override |
151 | public void onResult(boolean result) { | 149 | public void onResult(boolean result) { |
152 | if(result){ | 150 | if(result){ |
153 | //调用GameSDK.iap | 151 | //调用GameSDK.iap |
154 | }else{ | 152 | }else{ |
155 | //调用GameSDK.pay | 153 | //调用GameSDK.pay |
156 | } | 154 | } |
157 | } | 155 | } |
158 | }); | 156 | }); |
159 | ``` | 157 | ``` |
160 | 158 | ||
161 | 1)调用GameSDK.pay | 159 | 1)调用GameSDK.pay |
162 | 160 | ||
163 | ```java | 161 | ```java |
164 | Bundle payInfo = new Bundle(); | 162 | Bundle payInfo = new Bundle(); |
165 | payInfo.putString("product", "元宝"); | 163 | payInfo.putString("product", "元宝"); |
166 | payInfo.putFloat("amount", 40.0f); | 164 | payInfo.putFloat("amount", 40.0f); |
167 | payInfo.putString("extraInfo", "This is demo!"); | 165 | payInfo.putString("extraInfo", "This is demo!"); |
168 | payInfo.putString("serverId", "B4003"); | 166 | payInfo.putString("serverId", "B4003"); |
169 | payInfo.putString("roleId", "10010"); | 167 | payInfo.putString("roleId", "10010"); |
170 | payInfo.putString("currency","currency"); | 168 | payInfo.putString("currency","currency"); |
171 | GumpSDK.pay(MainActivity.this, payInfo,PurchaseCallback); | 169 | GumpSDK.pay(MainActivity.this, payInfo,PurchaseCallback); |
172 | ``` | 170 | ``` |
173 | 调用pay方法时,必须穿入一个bundle对象,包含如上字段,所有字段必须全部包含 | 171 | 调用pay方法时,必须穿入一个bundle对象,包含如上字段,所有字段必须全部包含 |
174 | 172 | ||
175 | 173 | ||
176 | 2)IAP支付 | 174 | 2)IAP支付 |
177 | 175 | ||
178 | ```java | 176 | ```java |
179 | Bundle payInfo = new Bundle(); | 177 | Bundle payInfo = new Bundle(); |
180 | payInfo.putString("product", "gp_skuId"); | 178 | payInfo.putString("product", "gp_skuId"); |
181 | payInfo.putFloat("amount", 0.1f); | 179 | payInfo.putFloat("amount", 0.1f); |
182 | payInfo.putString("extraInfo", "This is demo!"); | 180 | payInfo.putString("extraInfo", "This is demo!"); |
183 | payInfo.putString("serverId", "100"); | 181 | payInfo.putString("serverId", "100"); |
184 | payInfo.putString("roleId","100123"); | 182 | payInfo.putString("roleId","100123"); |
185 | GumpSDK.iap(MainActivity.this, payInfo, PurchaseCallback); | 183 | GumpSDK.iap(MainActivity.this, payInfo, PurchaseCallback); |
186 | ``` | 184 | ``` |
187 | 185 | ||
188 | 3)PurchaseCallback为支付状态回调接口,此接口含有3个方法 | 186 | 3)PurchaseCallback为支付状态回调接口,此接口含有3个方法 |
189 | 187 | ||
190 | ```java | 188 | ```java |
191 | @Override | 189 | @Override |
192 | public void onPurchaseCompleted() { | 190 | public void onPurchaseCompleted() { |
193 | Log.i(TAG,"purchase completed"); | 191 | Log.i(TAG,"purchase completed"); |
194 | } | 192 | } |
195 | 193 | ||
196 | @Override | 194 | @Override |
197 | public void onPurchaseError(int code, String msg) { | 195 | public void onPurchaseError(int code, String msg) { |
198 | Log.i(TAG,"purchase error"); | 196 | Log.i(TAG,"purchase error"); |
199 | } | 197 | } |
200 | 198 | ||
201 | @Override | 199 | @Override |
202 | public void onPurchaseCanceled() { | 200 | public void onPurchaseCanceled() { |
203 | Log.i(TAG,"purchase canceled"); | 201 | Log.i(TAG,"purchase canceled"); |
204 | } | 202 | } |
205 | ``` | 203 | ``` |
206 | 204 | ||
207 | #### 4.注销登录 | 205 | #### 4.注销登录 |
208 | 206 | ||
209 | ```java | 207 | ```java |
210 | GameSDK.logout(Activity); | 208 | GameSDK.logout(Activity); |
211 | ``` | 209 | ``` |
212 | 当此方法调用后,用户退出登录,并会通过LoginStateListener接口通知调用程序!为了便于用户切换登录账户,请在游戏内提供用户注销的触发按钮 | 210 | 当此方法调用后,用户退出登录,并会通过LoginStateListener接口通知调用程序!为了便于用户切换登录账户,请在游戏内提供用户注销的触发按钮 |
213 | #### 5.运营开关接口,若需要接入,会有我方运营人员提出需求,否则不需要接入(若对此接口不知所云,即可认为不需要接入,请自行忽略) | 211 | #### 5.运营开关接口,若需要接入,会有我方运营人员提出需求,否则不需要接入(若对此接口不知所云,即可认为不需要接入,请自行忽略) |
214 | 212 | ||
215 | ```java | 213 | ```java |
216 | GameSDK.inspectRiskLevel(this, new ResultCallback() { | 214 | GameSDK.inspectRiskLevel(this, new ResultCallback() { |
217 | @Override | 215 | @Override |
218 | public void onResult(boolean result) { | 216 | public void onResult(boolean result) { |
219 | Log.i(TAG,result?"There is some risks":"Nothing is risk"); | 217 | Log.i(TAG,result?"There is some risks":"Nothing is risk"); |
220 | } | 218 | } |
221 | }); | 219 | }); |
222 | ``` | 220 | ``` |
223 | 221 | ||
224 | ## 第二章 常量字段与代码 | 222 | ## 第二章 常量字段与代码 |
225 | ### 1.第三方登录平台(third_plat) | 223 | ### 1.第三方登录平台(third_plat) |
226 | | 常量字段 | 说明 | | 224 | | 常量字段 | 说明 | |
227 | |--------------------------------|--------------| | 225 | |--------------------------------|--------------| |
228 | |SDKSettings.THIRD_SUPPORT_FB | Facebook登录 | | 226 | |SDKSettings.THIRD_SUPPORT_FB | Facebook登录 | |
229 | |SDKSettings.THIRD_SUPPORT_GOOGLE| Google登录 | | 227 | |SDKSettings.THIRD_SUPPORT_GOOGLE| Google登录 | |
230 | |SDKSettings.THIRD_SUPPORT_LINE | Line登录 | | 228 | |SDKSettings.THIRD_SUPPORT_LINE | Line登录 | |
231 | 229 | ||
232 | ### 2.登录账户类型 | 230 | ### 2.登录账户类型 |
233 | | 常量字段 | 说明 | | 231 | | 常量字段 | 说明 | |
234 | |-------------------------------------|--------------| | 232 | |-------------------------------------|--------------| |
235 | |GumpPreference.ACCOUNT_TYPE_FB | Facebook用户 | | 233 | |GumpPreference.ACCOUNT_TYPE_FB | Facebook用户 | |
236 | |GumpPreference.ACCOUNT_TYPE_REG | Gump注册用户 | | 234 | |GumpPreference.ACCOUNT_TYPE_REG | Gump注册用户 | |
237 | |GumpPreference.ACCOUNT_TYPE_QUICK_REG| 游客 | | 235 | |GumpPreference.ACCOUNT_TYPE_QUICK_REG| 游客 | |
238 | |GumpPreference.ACCOUNT_TYPE_GOOGLE | Google用户 | | 236 | |GumpPreference.ACCOUNT_TYPE_GOOGLE | Google用户 | |
239 | |GumpPreference.ACCOUNT_TYPE_LINE | Line用户 | | 237 | |GumpPreference.ACCOUNT_TYPE_LINE | Line用户 | |
240 | 238 | ||
241 | 239 | ||
242 | 240 | ||
243 | ## 第三章 常见问题 | 241 | ## 第三章 常见问题 |
244 | ### 问题1: 如何避免混淆对SDK的影响? | 242 | ### 问题1: 如何避免混淆对SDK的影响? |
245 | 解答:有些开发者对接入了SDK的程序进行混淆时,有可能会覆盖某些java | 243 | 解答:有些开发者对接入了SDK的程序进行混淆时,有可能会覆盖某些java |
246 | 类,导致SDK无法正常工作,解决方法如下: | 244 | 类,导致SDK无法正常工作,解决方法如下: |
247 | Ø 请开发者在混淆配置文件proguard.cfg或proguard-project.txt的最后加上 | 245 | Ø 请开发者在混淆配置文件proguard.cfg或proguard-project.txt的最后加上 |
248 | 246 | ||
249 | -keepattributes *Annotation*,InnerClasses,SourceFile,LineNumberTable | 247 | -keepattributes *Annotation*,InnerClasses,SourceFile,LineNumberTable |
250 | -keep public class * extends android.app.Service | 248 | -keep public class * extends android.app.Service |
251 | -keep public class com.google.vending.licensing.ILicensingService | 249 | -keep public class com.google.vending.licensing.ILicensingService |
252 | -keep public class com.android.vending.licensing.ILicensingService | 250 | -keep public class com.android.vending.licensing.ILicensingService |
253 | -keep class com.gump.game.sdk.view.* {*;} | 251 | -keep class com.gump.game.sdk.view.* {*;} |
254 | -keep class com.gump.game.sdk.web.* {*;} | 252 | -keep class com.gump.game.sdk.web.* {*;} |
255 | 253 | ||
256 | 254 | ||
257 | | 255 | |
258 | 使得混淆的时候不会影响SDK的命名空间。 | 256 | 使得混淆的时候不会影响SDK的命名空间。 |