Commit 7b52014d1ad873d57095f02f7898643280020c10
1 parent
442dd93729
Exists in
master
version4.7.1
Showing 4 changed files with 17 additions and 19 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 26 | 39 | compileSdkVersion 27 |
| 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 27 |
| 54 | applicationId "mx.she.rd4" | ||
| 54 | versionCode 6 | 55 | versionCode 6 |
| 55 | versionName "1.4" | 56 | versionName "1.4" |
| 56 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | 57 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" |
| 57 | signingConfig signingConfigs.release | 58 | signingConfig signingConfigs.release |
| 58 | } | 59 | } |
| 59 | buildTypes { | 60 | buildTypes { |
| 60 | release { | 61 | release { |
| 61 | minifyEnabled false | 62 | minifyEnabled false |
| 62 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | 63 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' |
| 63 | zipAlignEnabled true | 64 | zipAlignEnabled true |
| 64 | } | 65 | } |
| 65 | debug { | 66 | debug { |
| 66 | signingConfig signingConfigs.release | 67 | signingConfig signingConfigs.release |
| 67 | } | 68 | } |
| 68 | } | 69 | } |
| 69 | lintOptions { | 70 | lintOptions { |
| 70 | abortOnError false | 71 | abortOnError false |
| 71 | } | 72 | } |
| 72 | 73 | compileOptions { | |
| 74 | sourceCompatibility JavaVersion.VERSION_1_7 | ||
| 75 | targetCompatibility JavaVersion.VERSION_1_7 | ||
| 76 | } | ||
| 73 | applicationVariants.all { | 77 | applicationVariants.all { |
| 74 | variant -> | 78 | variant -> |
| 75 | variant.outputs.all { | 79 | variant.outputs.all { |
| 76 | outputFileName = "GameSDKDemo-" + variant.name + defaultConfig.versionName + ".apk" | 80 | outputFileName = "GameSDKDemo-" + variant.name + defaultConfig.versionName + ".apk" |
| 77 | } | 81 | } |
| 78 | } | 82 | } |
| 79 | 83 | ||
| 80 | } | 84 | } |
| 81 | 85 | ||
| 82 | dependencies { | 86 | dependencies { |
| 83 | implementation fileTree(include: ['*.jar'], dir: 'libs') | 87 | implementation fileTree(include: ['*.jar'], dir: 'libs') |
| 84 | implementation 'com.android.support:support-v4:26.1.0' | 88 | implementation 'com.android.support:support-v4:27.1.1' |
| 85 | testImplementation 'junit:junit:4.12' | 89 | testImplementation 'junit:junit:4.12' |
| 86 | implementation 'com.android.support:appcompat-v7:26.1.0' | 90 | implementation 'com.android.support:appcompat-v7:27.1.1' |
| 87 | implementation 'com.android.support:design:26.1.0' | 91 | implementation 'com.android.support:design:27.1.1' |
| 88 | // implementation project(':GameSDK') | 92 | // implementation project(':GameSDK') |
| 89 | // implementation project(':IAP5Helper') | 93 | // implementation project(':IAP5Helper') |
| 90 | implementation 'com.gumptech.sdk:GameSDK:4.7.0' | 94 | implementation 'com.gumptech.sdk:GameSDK:4.7.1' |
| 91 | // implementation 'com.gumptech.sdk:SamsungIAP:5.1.1' | 95 | // implementation 'com.gumptech.sdk:SamsungIAP:5.1.1' |
| 92 | } | 96 | } |
| 93 | 97 |
GameSDKDemo/src/main/java/com/gumptech/sdk/demo/MainActivity.java
| 1 | package com.gumptech.sdk.demo; | 1 | package com.gumptech.sdk.demo; |
| 2 | 2 | ||
| 3 | import android.os.Bundle; | 3 | import android.os.Bundle; |
| 4 | import android.support.v7.app.AppCompatActivity; | 4 | import android.support.v7.app.AppCompatActivity; |
| 5 | import android.util.Log; | 5 | import android.util.Log; |
| 6 | import android.view.View; | 6 | import android.view.View; |
| 7 | import android.widget.Button; | 7 | import android.widget.Button; |
| 8 | import android.widget.TextView; | 8 | import android.widget.TextView; |
| 9 | import android.widget.Toast; | 9 | import android.widget.Toast; |
| 10 | 10 | ||
| 11 | import com.gumptech.sdk.GumpPreference; | 11 | import com.gumptech.sdk.GumpPreference; |
| 12 | import com.gumptech.sdk.GumpSDK; | 12 | import com.gumptech.sdk.GumpSDK; |
| 13 | import com.gumptech.sdk.PaymentVersion; | 13 | import com.gumptech.sdk.PaymentVersion; |
| 14 | import com.gumptech.sdk.SDKSettings; | 14 | import com.gumptech.sdk.SDKSettings; |
| 15 | import com.gumptech.sdk.bean.GumpUser; | 15 | import com.gumptech.sdk.bean.GumpUser; |
| 16 | import com.gumptech.sdk.bean.PurchaseResult; | 16 | import com.gumptech.sdk.bean.PurchaseResult; |
| 17 | import com.gumptech.sdk.callback.InitializeCallback; | 17 | import com.gumptech.sdk.callback.InitializeCallback; |
| 18 | import com.gumptech.sdk.callback.LoginStateListener; | 18 | import com.gumptech.sdk.callback.LoginStateListener; |
| 19 | import com.gumptech.sdk.callback.PurchaseCallback; | 19 | import com.gumptech.sdk.callback.PurchaseCallback; |
| 20 | import com.gumptech.sdk.callback.ResultCallback; | 20 | import com.gumptech.sdk.callback.ResultCallback; |
| 21 | import com.gumptech.sdk.passport.fb.FBAccessToken; | 21 | import com.gumptech.sdk.passport.fb.FBAccessToken; |
| 22 | 22 | ||
| 23 | import java.util.Locale; | 23 | import java.util.Locale; |
| 24 | 24 | ||
| 25 | public class MainActivity extends AppCompatActivity implements PurchaseCallback { | 25 | public class MainActivity extends AppCompatActivity implements PurchaseCallback { |
| 26 | 26 | ||
| 27 | private static final String TAG = "MainActivity"; | 27 | private static final String TAG = "MainActivity"; |
| 28 | 28 | ||
| 29 | private TextView tvVersion; | 29 | private TextView tvVersion; |
| 30 | private TextView userInfo; | 30 | private TextView userInfo; |
| 31 | 31 | ||
| 32 | private Button btnLoginOrLogout; | 32 | private Button btnLoginOrLogout; |
| 33 | private Button btnInit; | 33 | private Button btnInit; |
| 34 | private Button btnCheckState; | 34 | private Button btnCheckState; |
| 35 | private Button btnPay; | 35 | private Button btnPay; |
| 36 | private Button btnIap; | 36 | private Button btnIap; |
| 37 | 37 | ||
| 38 | private String appId = "100"; | 38 | private String appId = "10036"; |
| 39 | private String appKey = "f899139df5e1059396431415e770c6dd"; | 39 | private String appKey = "7c127e0c66f06e58c7c7310a7c6fa488"; |
| 40 | private GumpUser gumpUser; | 40 | private GumpUser gumpUser; |
| 41 | 41 | ||
| 42 | /** | 42 | /** |
| 43 | * 测试数据 | 43 | * 测试数据 |
| 44 | */ | 44 | */ |
| 45 | String serverId = "100"; | 45 | String serverId = "100"; |
| 46 | String roleId = "41080"; | 46 | String roleId = "41080"; |
| 47 | String product = "test"; | ||
| 48 | 47 | ||
| 49 | 48 | ||
| 50 | @Override | 49 | @Override |
| 51 | protected void onCreate(Bundle savedInstanceState) { | 50 | protected void onCreate(Bundle savedInstanceState) { |
| 52 | super.onCreate(savedInstanceState); | 51 | super.onCreate(savedInstanceState); |
| 53 | setContentView(R.layout.activity_main); | 52 | setContentView(R.layout.activity_main); |
| 54 | 53 | ||
| 55 | tvVersion = findViewById(R.id.version); | 54 | tvVersion = findViewById(R.id.version); |
| 56 | userInfo = findViewById(R.id.user_info); | 55 | userInfo = findViewById(R.id.user_info); |
| 57 | btnLoginOrLogout = findViewById(R.id.login_or_logout); | 56 | btnLoginOrLogout = findViewById(R.id.login_or_logout); |
| 58 | btnInit = findViewById(R.id.init); | 57 | btnInit = findViewById(R.id.init); |
| 59 | btnCheckState = findViewById(R.id.check_state); | 58 | btnCheckState = findViewById(R.id.check_state); |
| 60 | btnLoginOrLogout.setOnClickListener(new View.OnClickListener() { | 59 | btnLoginOrLogout.setOnClickListener(new View.OnClickListener() { |
| 61 | 60 | ||
| 62 | @Override | 61 | @Override |
| 63 | public void onClick(View v) { | 62 | public void onClick(View v) { |
| 64 | if (btnLoginOrLogout.getTag() == null || (Integer) btnLoginOrLogout.getTag() == 0) | 63 | if (btnLoginOrLogout.getTag() == null || (Integer) btnLoginOrLogout.getTag() == 0) |
| 65 | GumpSDK.start(MainActivity.this); | 64 | GumpSDK.start(MainActivity.this); |
| 66 | else | 65 | else |
| 67 | GumpSDK.logout(MainActivity.this); | 66 | GumpSDK.logout(MainActivity.this); |
| 68 | } | 67 | } |
| 69 | }); | 68 | }); |
| 70 | btnInit.setOnClickListener(new View.OnClickListener() { | 69 | btnInit.setOnClickListener(new View.OnClickListener() { |
| 71 | @Override | 70 | @Override |
| 72 | public void onClick(View v) { | 71 | public void onClick(View v) { |
| 73 | btnInit.setEnabled(false); | 72 | btnInit.setEnabled(false); |
| 74 | GumpSDK.init(getApplicationContext(), appId, appKey, "1000", new InitializeCallback() { | 73 | GumpSDK.init(getApplicationContext(), appId, appKey, "1000", new InitializeCallback() { |
| 75 | @Override | 74 | @Override |
| 76 | public void initComplete(int result) { | 75 | public void initComplete(int result) { |
| 77 | if (result == GumpSDK.CODE.OK) { | 76 | if (result == GumpSDK.CODE.OK) { |
| 78 | btnLoginOrLogout.setEnabled(true); | 77 | btnLoginOrLogout.setEnabled(true); |
| 79 | userInfo.setText("initialization has finished"); | 78 | userInfo.setText("initialization has finished"); |
| 80 | } else { | 79 | } else { |
| 81 | btnInit.setEnabled(true); | 80 | btnInit.setEnabled(true); |
| 82 | userInfo.setText("initialization has error"); | 81 | userInfo.setText("initialization has error"); |
| 83 | } | 82 | } |
| 84 | } | 83 | } |
| 85 | }); | 84 | }); |
| 86 | } | 85 | } |
| 87 | }); | 86 | }); |
| 88 | btnCheckState.setOnClickListener(new View.OnClickListener() { | 87 | btnCheckState.setOnClickListener(new View.OnClickListener() { |
| 89 | @Override | 88 | @Override |
| 90 | public void onClick(View v) { | 89 | public void onClick(View v) { |
| 91 | // btnCheckState.setEnabled(false); | 90 | // btnCheckState.setEnabled(false); |
| 92 | GumpSDK.shouldUseCoPay(MainActivity.this, serverId, roleId, new ResultCallback() { | 91 | GumpSDK.shouldUseCoPay(MainActivity.this, serverId, roleId, new ResultCallback() { |
| 93 | @Override | 92 | @Override |
| 94 | public void onResult(boolean isRisk) { | 93 | public void onResult(boolean isRisk) { |
| 95 | btnIap.setEnabled(isRisk); | 94 | btnIap.setEnabled(isRisk); |
| 96 | btnPay.setEnabled(!isRisk); | 95 | btnPay.setEnabled(!isRisk); |
| 97 | } | 96 | } |
| 98 | }); | 97 | }); |
| 99 | } | 98 | } |
| 100 | }); | 99 | }); |
| 101 | btnPay = findViewById(R.id.pay); | 100 | btnPay = findViewById(R.id.pay); |
| 102 | btnPay.setOnClickListener(new View.OnClickListener() { | 101 | btnPay.setOnClickListener(new View.OnClickListener() { |
| 103 | 102 | ||
| 104 | @Override | 103 | @Override |
| 105 | public void onClick(View v) { | 104 | public void onClick(View v) { |
| 106 | PaymentInfoSubmitFragment submitFragment = PaymentInfoSubmitFragment.newInstance(new PaymentInfoSubmitFragment.OnSubmitListener() { | 105 | PaymentInfoSubmitFragment submitFragment = PaymentInfoSubmitFragment.newInstance(new PaymentInfoSubmitFragment.OnSubmitListener() { |
| 107 | @Override | 106 | @Override |
| 108 | public void onSubmit(Bundle payInfo) { | 107 | public void onSubmit(Bundle payInfo) { |
| 109 | GumpSDK.pay(MainActivity.this, payInfo, MainActivity.this); | 108 | GumpSDK.pay(MainActivity.this, payInfo, MainActivity.this); |
| 110 | } | 109 | } |
| 111 | }); | 110 | }); |
| 112 | // Bundle payInfo = new Bundle(); | 111 | // Bundle payInfo = new Bundle(); |
| 113 | // payInfo.putString("product", "test"); | 112 | // payInfo.putString("product", "test"); |
| 114 | // payInfo.putFloat("amount", 0.1f); | 113 | // payInfo.putFloat("amount", 0.1f); |
| 115 | // payInfo.putString("extraInfo", "This is demo!"); | 114 | // payInfo.putString("extraInfo", "This is demo!"); |
| 116 | // payInfo.putString("serverId", "s1"); | 115 | // payInfo.putString("serverId", "s1"); |
| 117 | // payInfo.putString("roleId", "100123"); | 116 | // payInfo.putString("roleId", "100123"); |
| 118 | // payInfo.putString("currency", "THB"); | 117 | // payInfo.putString("currency", "THB"); |
| 119 | submitFragment.show(getSupportFragmentManager(), "pay"); | 118 | submitFragment.show(getSupportFragmentManager(), "pay"); |
| 120 | } | 119 | } |
| 121 | }); | 120 | }); |
| 122 | btnIap = findViewById(R.id.iap); | 121 | btnIap = findViewById(R.id.iap); |
| 123 | btnIap.setOnClickListener(new View.OnClickListener() { | 122 | btnIap.setOnClickListener(new View.OnClickListener() { |
| 124 | @Override | 123 | @Override |
| 125 | public void onClick(View v) { | 124 | public void onClick(View v) { |
| 126 | PaymentInfoSubmitFragment submitFragment = PaymentInfoSubmitFragment.newInstance(new PaymentInfoSubmitFragment.OnSubmitListener() { | 125 | PaymentInfoSubmitFragment submitFragment = PaymentInfoSubmitFragment.newInstance(new PaymentInfoSubmitFragment.OnSubmitListener() { |
| 127 | @Override | 126 | @Override |
| 128 | public void onSubmit(Bundle payInfo) { | 127 | public void onSubmit(Bundle payInfo) { |
| 129 | GumpSDK.iap(MainActivity.this, payInfo, MainActivity.this); | 128 | GumpSDK.iap(MainActivity.this, payInfo, MainActivity.this); |
| 130 | } | 129 | } |
| 131 | }); | 130 | }); |
| 132 | submitFragment.show(getSupportFragmentManager(), "iap"); | 131 | submitFragment.show(getSupportFragmentManager(), "iap"); |
| 133 | // Bundle payInfo = new Bundle(); | 132 | // Bundle payInfo = new Bundle(); |
| 134 | // payInfo.putString("product", "dwe"); | 133 | // payInfo.putString("product", "dwe"); |
| 135 | // payInfo.putFloat("amount", 0.1f); | 134 | // payInfo.putFloat("amount", 0.1f); |
| 136 | // payInfo.putString("extraInfo", "This is demo!"); | 135 | // payInfo.putString("extraInfo", "This is demo!"); |
| 137 | // payInfo.putString("serverId", serverId); | 136 | // payInfo.putString("serverId", serverId); |
| 138 | // payInfo.putString("roleId", "100123"); | 137 | // payInfo.putString("roleId", "100123"); |
| 139 | // payInfo.putString("currency", "THB"); | 138 | // payInfo.putString("currency", "THB"); |
| 140 | // GumpSDK.iap(MainActivity.this, payInfo, MainActivity.this); | 139 | // GumpSDK.iap(MainActivity.this, payInfo, MainActivity.this); |
| 141 | } | 140 | } |
| 142 | }); | 141 | }); |
| 143 | 142 | ||
| 144 | 143 | ||
| 145 | Log.i("DEMO", "country:" + Locale.getDefault().getCountry() + ",language:" + Locale.getDefault().getLanguage()); | 144 | Log.i("DEMO", "country:" + Locale.getDefault().getCountry() + ",language:" + Locale.getDefault().getLanguage()); |
| 146 | 145 | ||
| 147 | GumpSDK.getSettings().setDebug(false); | 146 | GumpSDK.getSettings().setDebug(false); |
| 148 | /** | 147 | /** |
| 149 | * 设置是否打印debug日志 | 148 | * 设置是否打印debug日志 |
| 150 | */ | 149 | */ |
| 151 | GumpSDK.getSettings().enableDebugLogging(true); | 150 | GumpSDK.getSettings().enableDebugLogging(true); |
| 152 | /** | 151 | /** |
| 153 | * 设置启用facebook登录 | 152 | * 设置启用facebook登录 |
| 154 | */ | 153 | */ |
| 155 | GumpSDK.getSettings().requestThirdSupport(SDKSettings.THIRD_SUPPORT_FB); | 154 | GumpSDK.getSettings().requestThirdSupport(SDKSettings.THIRD_SUPPORT_FB); |
| 156 | 155 | ||
| 157 | /** | 156 | /** |
| 158 | * 设置启用google登录 | 157 | * 设置启用google登录 |
| 159 | */ | 158 | */ |
| 160 | GumpSDK.getSettings().requestThirdSupport(SDKSettings.THIRD_SUPPORT_GOOGLE); | 159 | GumpSDK.getSettings().requestThirdSupport(SDKSettings.THIRD_SUPPORT_GOOGLE); |
| 161 | 160 | ||
| 162 | /** | 161 | /** |
| 163 | * 设置启用Line登录 | 162 | * 设置启用Line登录 |
| 164 | */ | 163 | */ |
| 165 | GumpSDK.getSettings().requestThirdSupport(SDKSettings.THIRD_SUPPORT_LINE); | 164 | GumpSDK.getSettings().requestThirdSupport(SDKSettings.THIRD_SUPPORT_LINE); |
| 166 | 165 | ||
| 167 | /** | 166 | /** |
| 168 | * 设置支付版本 | 167 | * 设置支付版本 |
| 169 | */ | 168 | */ |
| 170 | GumpSDK.getSettings().setPaymentVersion(PaymentVersion.V4); | 169 | GumpSDK.getSettings().setPaymentVersion(PaymentVersion.V4); |
| 171 | 170 | ||
| 172 | /** | 171 | /** |
| 173 | * 设置用户登录状态监听器 | 172 | * 设置用户登录状态监听器 |
| 174 | */ | 173 | */ |
| 175 | 174 | ||
| 176 | GumpSDK.setUserStateListener(new LoginStateListener() { | 175 | GumpSDK.setUserStateListener(new LoginStateListener() { |
| 177 | @Override | 176 | @Override |
| 178 | public void onLoginSuccess(GumpUser user) { | 177 | public void onLoginSuccess(GumpUser user) { |
| 179 | btnCheckState.setEnabled(true); | 178 | btnCheckState.setEnabled(true); |
| 180 | gumpUser = user; | 179 | gumpUser = user; |
| 181 | String userType = null; | 180 | String userType = null; |
| 182 | switch (user.getAccountType()) { | 181 | switch (user.getAccountType()) { |
| 183 | case GumpPreference.ACCOUNT_TYPE_FB: | 182 | case GumpPreference.ACCOUNT_TYPE_FB: |
| 184 | userType = "Facebook登录"; | 183 | userType = "Facebook登录"; |
| 185 | String fbToken = FBAccessToken.getCurrentAccessToken().getToken(); | 184 | String fbToken = FBAccessToken.getCurrentAccessToken().getToken(); |
| 186 | Log.d(TAG, "FBAccessToken:" + fbToken); | 185 | Log.d(TAG, "FBAccessToken:" + fbToken); |
| 187 | break; | 186 | break; |
| 188 | case GumpPreference.ACCOUNT_TYPE_QUICK_REG: | 187 | case GumpPreference.ACCOUNT_TYPE_QUICK_REG: |
| 189 | userType = "快速登录"; | 188 | userType = "快速登录"; |
| 190 | break; | 189 | break; |
| 191 | case GumpPreference.ACCOUNT_TYPE_REG: | 190 | case GumpPreference.ACCOUNT_TYPE_REG: |
| 192 | userType = "gump注册用户"; | 191 | userType = "gump注册用户"; |
| 193 | break; | 192 | break; |
| 194 | case GumpPreference.ACCOUNT_TYPE_GOOGLE: | 193 | case GumpPreference.ACCOUNT_TYPE_GOOGLE: |
| 195 | userType = "google 登录"; | 194 | userType = "google 登录"; |
| 196 | break; | 195 | break; |
| 197 | case GumpPreference.ACCOUNT_TYPE_LINE: | 196 | case GumpPreference.ACCOUNT_TYPE_LINE: |
| 198 | userType = "Line登录"; | 197 | userType = "Line登录"; |
| 199 | break; | 198 | break; |
| 200 | } | 199 | } |
| 201 | userInfo.setText(" Userid:" + user.getUid() + "\n accountType:(" + user.getAccountType() + ") " + userType + "\n sessionKey:" + user.getSessionKey() | 200 | userInfo.setText(" Userid:" + user.getUid() + "\n accountType:(" + user.getAccountType() + ") " + userType + "\n sessionKey:" + user.getSessionKey() |
| 202 | .getToken()); | 201 | .getToken()); |
| 203 | btnLoginOrLogout.setText("Logout"); | 202 | btnLoginOrLogout.setText("Logout"); |
| 204 | btnLoginOrLogout.setTag(1); | 203 | btnLoginOrLogout.setTag(1); |
| 205 | } | 204 | } |
| 206 | 205 | ||
| 207 | @Override | 206 | @Override |
| 208 | public void onLoginFailed(int code, String msg) { | 207 | public void onLoginFailed(int code, String msg) { |
| 209 | userInfo.setText(msg); | 208 | userInfo.setText(msg); |
| 210 | Toast.makeText(MainActivity.this, "Login failed:code=" + code + ",message=" + msg, Toast.LENGTH_SHORT).show(); | 209 | Toast.makeText(MainActivity.this, "Login failed:code=" + code + ",message=" + msg, Toast.LENGTH_SHORT).show(); |
| 211 | } | 210 | } |
| 212 | 211 | ||
| 213 | @Override | 212 | @Override |
| 214 | public void onLoginCanceled() { | 213 | public void onLoginCanceled() { |
| 215 | Toast.makeText(MainActivity.this, "operate be canceled", Toast.LENGTH_SHORT).show(); | 214 | Toast.makeText(MainActivity.this, "operate be canceled", Toast.LENGTH_SHORT).show(); |
| 216 | } | 215 | } |
| 217 | 216 | ||
| 218 | @Override | 217 | @Override |
| 219 | public void onLogout() { | 218 | public void onLogout() { |
| 220 | btnLoginOrLogout.setText("Login"); | 219 | btnLoginOrLogout.setText("Login"); |
| 221 | btnLoginOrLogout.setTag(0); | 220 | btnLoginOrLogout.setTag(0); |
| 222 | userInfo.setText("User is logout"); | 221 | userInfo.setText("User is logout"); |
| 223 | } | 222 | } |
| 224 | 223 | ||
| 225 | @Override | 224 | @Override |
| 226 | public void onPermissionDenied(String[] deniedPermissions) { | 225 | public void onPermissionDenied(String[] deniedPermissions) { |
| 227 | StringBuilder sb = new StringBuilder(); | 226 | StringBuilder sb = new StringBuilder(); |
| 228 | for (String s : deniedPermissions) { | 227 | for (String s : deniedPermissions) { |
| 229 | sb.append(s); | 228 | sb.append(s); |
| 230 | sb.append(","); | 229 | sb.append(","); |
| 231 | } | 230 | } |
| 232 | Toast.makeText(MainActivity.this, "Permission denied:" + sb.toString(), Toast.LENGTH_SHORT).show(); | 231 | Toast.makeText(MainActivity.this, "Permission denied:" + sb.toString(), Toast.LENGTH_SHORT).show(); |
| 233 | } | 232 | } |
| 234 | }); | 233 | }); |
| 235 | /** | 234 | /** |
| 236 | * 初始化sdk | 235 | * 初始化sdk |
| 237 | */ | 236 | */ |
| 238 | GumpSDK.init(getApplicationContext(), appId, appKey, "1000", new InitializeCallback() { | 237 | GumpSDK.init(getApplicationContext(), appId, appKey, "1000", new InitializeCallback() { |
| 239 | @Override | 238 | @Override |
| 240 | public void initComplete(int result) { | 239 | public void initComplete(int result) { |
| 241 | if (result == GumpSDK.CODE.OK) { | 240 | if (result == GumpSDK.CODE.OK) { |
| 242 | btnLoginOrLogout.setEnabled(true); | 241 | btnLoginOrLogout.setEnabled(true); |
| 243 | userInfo.setText("initialization has finished"); | 242 | userInfo.setText("initialization has finished"); |
| 244 | 243 | ||
| 245 | //checkRisk(); | 244 | //checkRisk(); |
| 246 | } else { | 245 | } else { |
| 247 | btnInit.setEnabled(true); | 246 | btnInit.setEnabled(true); |
| 248 | userInfo.setText("initialization has error"); | 247 | userInfo.setText("initialization has error"); |
| 249 | } | 248 | } |
| 250 | } | 249 | } |
| 251 | }); | 250 | }); |
| 252 | 251 | ||
| 253 | tvVersion.setText("SDK Version:" + GumpSDK.getVersion()); | 252 | tvVersion.setText("SDK Version:" + GumpSDK.getVersion()); |
| 254 | 253 | ||
| 255 | } | 254 | } |
| 256 | 255 | ||
| 257 | private void checkRisk() { | 256 | private void checkRisk() { |
| 258 | GumpSDK.checkRisk(this, new ResultCallback() { | 257 | GumpSDK.checkRisk(this, new ResultCallback() { |
| 259 | @Override | 258 | @Override |
| 260 | public void onResult(boolean isRisk) { | 259 | public void onResult(boolean isRisk) { |
| 261 | Log.i(TAG, isRisk ? "There is some risks" : "Nothing is risk"); | 260 | Log.i(TAG, isRisk ? "There is some risks" : "Nothing is risk"); |
| 262 | } | 261 | } |
| 263 | }); | 262 | }); |
| 264 | } | 263 | } |
| 265 | 264 | ||
| 266 | @Override | 265 | @Override |
| 267 | public void onPurchaseCompleted(PurchaseResult result) { | 266 | public void onPurchaseCompleted(PurchaseResult result) { |
| 268 | Log.i(TAG, "purchase completed"); | 267 | Log.i(TAG, "purchase completed"); |
| 269 | } | 268 | } |
| 270 | 269 | ||
| 271 | @Override | 270 | @Override |
| 272 | public void onPurchaseError(int code, String msg) { | 271 | public void onPurchaseError(int code, String msg) { |
| 273 | Log.i(TAG, "purchase error"); | 272 | Log.i(TAG, "purchase error:"+code+","+msg); |
| 274 | } | 273 | } |
| 275 | 274 | ||
| 276 | @Override | 275 | @Override |
| 277 | public void onPurchaseCanceled() { | 276 | public void onPurchaseCanceled() { |
| 278 | Log.i(TAG, "purchase canceled"); | 277 | Log.i(TAG, "purchase canceled"); |
| 279 | } | 278 | } |
| 280 | 279 | ||
| 281 | 280 | ||
| 282 | } | 281 | } |
| 283 | 282 |
GameSDKDemo/src/main/java/com/gumptech/sdk/demo/PaymentInfoSubmitFragment.java
| 1 | package com.gumptech.sdk.demo; | 1 | package com.gumptech.sdk.demo; |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | import android.app.AlertDialog; | 4 | import android.app.AlertDialog; |
| 5 | import android.app.Dialog; | 5 | import android.app.Dialog; |
| 6 | import android.os.Bundle; | 6 | import android.os.Bundle; |
| 7 | import android.support.annotation.NonNull; | 7 | import android.support.annotation.NonNull; |
| 8 | import android.support.design.widget.TextInputLayout; | 8 | import android.support.design.widget.TextInputLayout; |
| 9 | import android.support.v4.app.DialogFragment; | 9 | import android.support.v4.app.DialogFragment; |
| 10 | import android.support.v4.app.Fragment; | ||
| 11 | import android.text.Editable; | 10 | import android.text.Editable; |
| 12 | import android.text.TextUtils; | 11 | import android.text.TextUtils; |
| 13 | import android.text.TextWatcher; | 12 | import android.text.TextWatcher; |
| 14 | import android.view.LayoutInflater; | 13 | import android.view.LayoutInflater; |
| 15 | import android.view.View; | 14 | import android.view.View; |
| 16 | 15 | ||
| 17 | 16 | ||
| 18 | /** | 17 | |
| 19 | * A simple {@link Fragment} subclass. | ||
| 20 | */ | ||
| 21 | public class PaymentInfoSubmitFragment extends DialogFragment { | 18 | public class PaymentInfoSubmitFragment extends DialogFragment { |
| 22 | 19 | ||
| 23 | interface OnSubmitListener { | 20 | interface OnSubmitListener { |
| 24 | void onSubmit(Bundle payInfo); | 21 | void onSubmit(Bundle payInfo); |
| 25 | } | 22 | } |
| 26 | 23 | ||
| 27 | private OnSubmitListener listener; | 24 | private OnSubmitListener listener; |
| 28 | 25 | ||
| 29 | TextInputLayout etProduct, | 26 | TextInputLayout etProduct, |
| 30 | etAmount, | 27 | etAmount, |
| 31 | etCurrency, | 28 | etCurrency, |
| 32 | etServerId, | 29 | etServerId, |
| 33 | etRoleId, | 30 | etRoleId, |
| 34 | etExtra; | 31 | etExtra; |
| 35 | 32 | ||
| 36 | public PaymentInfoSubmitFragment() { | ||
| 37 | 33 | ||
| 38 | } | ||
| 39 | 34 | ||
| 40 | public static PaymentInfoSubmitFragment newInstance(OnSubmitListener listener) { | 35 | public static PaymentInfoSubmitFragment newInstance(OnSubmitListener listener) { |
| 41 | PaymentInfoSubmitFragment fragment = new PaymentInfoSubmitFragment(); | 36 | PaymentInfoSubmitFragment fragment = new PaymentInfoSubmitFragment(); |
| 42 | fragment.listener = listener; | 37 | fragment.listener = listener; |
| 43 | return fragment; | 38 | return fragment; |
| 44 | } | 39 | } |
| 45 | 40 | ||
| 46 | @NonNull | 41 | @NonNull |
| 47 | @Override | 42 | @Override |
| 48 | public Dialog onCreateDialog(Bundle savedInstanceState) { | 43 | public Dialog onCreateDialog(Bundle savedInstanceState) { |
| 49 | AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); | 44 | AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); |
| 50 | View view = LayoutInflater.from(getContext()).inflate(R.layout.fragment_payment, null, false); | 45 | View view = LayoutInflater.from(getContext()).inflate(R.layout.fragment_payment, null, false); |
| 51 | etProduct = view.findViewById(R.id.product); | 46 | etProduct = view.findViewById(R.id.product); |
| 52 | etAmount = view.findViewById(R.id.amount); | 47 | etAmount = view.findViewById(R.id.amount); |
| 53 | etCurrency = view.findViewById(R.id.currency); | 48 | etCurrency = view.findViewById(R.id.currency); |
| 54 | etServerId = view.findViewById(R.id.server_id); | 49 | etServerId = view.findViewById(R.id.server_id); |
| 55 | etRoleId = view.findViewById(R.id.role_id); | 50 | etRoleId = view.findViewById(R.id.role_id); |
| 56 | etExtra = view.findViewById(R.id.extra); | 51 | etExtra = view.findViewById(R.id.extra); |
| 57 | etProduct.getEditText().addTextChangedListener(new EditTextWatcher(etProduct)); | 52 | etProduct.getEditText().addTextChangedListener(new EditTextWatcher(etProduct)); |
| 58 | etAmount.getEditText().addTextChangedListener(new EditTextWatcher(etAmount)); | 53 | etAmount.getEditText().addTextChangedListener(new EditTextWatcher(etAmount)); |
| 59 | etCurrency.getEditText().addTextChangedListener(new EditTextWatcher(etCurrency)); | 54 | etCurrency.getEditText().addTextChangedListener(new EditTextWatcher(etCurrency)); |
| 60 | etServerId.getEditText().addTextChangedListener(new EditTextWatcher(etServerId)); | 55 | etServerId.getEditText().addTextChangedListener(new EditTextWatcher(etServerId)); |
| 61 | etRoleId.getEditText().addTextChangedListener(new EditTextWatcher(etRoleId)); | 56 | etRoleId.getEditText().addTextChangedListener(new EditTextWatcher(etRoleId)); |
| 62 | etExtra.getEditText().addTextChangedListener(new EditTextWatcher(etExtra)); | 57 | etExtra.getEditText().addTextChangedListener(new EditTextWatcher(etExtra)); |
| 63 | //设置默认值 | 58 | //设置默认值 |
| 64 | etProduct.getEditText().setText("EV1.test.abc"); | 59 | etProduct.getEditText().setText("EV1.test.abc"); |
| 65 | etAmount.getEditText().setText("0.99"); | 60 | etAmount.getEditText().setText("0.99"); |
| 66 | etCurrency.getEditText().setText("USD"); | 61 | etCurrency.getEditText().setText("USD"); |
| 67 | etServerId.getEditText().setText("100"); | 62 | etServerId.getEditText().setText("100"); |
| 68 | etRoleId.getEditText().setText("41080"); | 63 | etRoleId.getEditText().setText("41080"); |
| 69 | view.findViewById(R.id.submit).setOnClickListener(new View.OnClickListener() { | 64 | view.findViewById(R.id.submit).setOnClickListener(new View.OnClickListener() { |
| 70 | @Override | 65 | @Override |
| 71 | public void onClick(View v) { | 66 | public void onClick(View v) { |
| 72 | String product = etProduct.getEditText().getText().toString(); | 67 | String product = etProduct.getEditText().getText().toString(); |
| 73 | String currency = etCurrency.getEditText().getText().toString(); | 68 | String currency = etCurrency.getEditText().getText().toString(); |
| 74 | String serverId = etServerId.getEditText().getText().toString(); | 69 | String serverId = etServerId.getEditText().getText().toString(); |
| 75 | String roleId = etRoleId.getEditText().getText().toString(); | 70 | String roleId = etRoleId.getEditText().getText().toString(); |
| 76 | String extra = etExtra.getEditText().getText().toString(); | 71 | String extra = etExtra.getEditText().getText().toString(); |
| 77 | String amount = etAmount.getEditText().getText().toString(); | 72 | String amount = etAmount.getEditText().getText().toString(); |
| 78 | if (checkInput(product, amount, currency, serverId, roleId, extra)) { | 73 | if (checkInput(product, amount, currency, serverId, roleId, extra)) { |
| 79 | Bundle payInfo = new Bundle(); | 74 | Bundle payInfo = new Bundle(); |
| 80 | payInfo.putString("product", product); | 75 | payInfo.putString("product", product); |
| 81 | payInfo.putFloat("amount", Float.valueOf(amount)); | 76 | payInfo.putFloat("amount", Float.valueOf(amount)); |
| 82 | payInfo.putString("extraInfo", extra); | 77 | payInfo.putString("extraInfo", extra); |
| 83 | payInfo.putString("serverId", serverId); | 78 | payInfo.putString("serverId", serverId); |
| 84 | payInfo.putString("roleId", roleId); | 79 | payInfo.putString("roleId", roleId); |
| 85 | payInfo.putString("currency", currency); | 80 | payInfo.putString("currency", currency); |
| 86 | if (listener != null) { | 81 | if (listener != null) { |
| 87 | listener.onSubmit(payInfo); | 82 | listener.onSubmit(payInfo); |
| 88 | } | 83 | } |
| 89 | dismiss(); | 84 | dismiss(); |
| 90 | } | 85 | } |
| 91 | } | 86 | } |
| 92 | }); | 87 | }); |
| 93 | AlertDialog dialog = builder.setView(view).create(); | 88 | AlertDialog dialog = builder.setView(view).create(); |
| 94 | return dialog; | 89 | return dialog; |
| 95 | } | 90 | } |
| 96 | 91 | ||
| 97 | 92 | ||
| 98 | private boolean checkInput(String product, String amount, String currency, String serverId, String roleId, String extra) { | 93 | private boolean checkInput(String product, String amount, String currency, String serverId, String roleId, String extra) { |
| 99 | if (TextUtils.isEmpty(product)) { | 94 | if (TextUtils.isEmpty(product)) { |
| 100 | etProduct.setError("product is empty"); | 95 | etProduct.setError("product is empty"); |
| 101 | return false; | 96 | return false; |
| 102 | } | 97 | } |
| 103 | if (TextUtils.isEmpty(currency)) { | 98 | if (TextUtils.isEmpty(currency)) { |
| 104 | etCurrency.setError("currency is empty"); | 99 | etCurrency.setError("currency is empty"); |
| 105 | return false; | 100 | return false; |
| 106 | } | 101 | } |
| 107 | if (TextUtils.isEmpty(serverId)) { | 102 | if (TextUtils.isEmpty(serverId)) { |
| 108 | etServerId.setError("serverId is empty"); | 103 | etServerId.setError("serverId is empty"); |
| 109 | return false; | 104 | return false; |
| 110 | } | 105 | } |
| 111 | if (TextUtils.isEmpty(roleId)) { | 106 | if (TextUtils.isEmpty(roleId)) { |
| 112 | etRoleId.setError("roleId is empty"); | 107 | etRoleId.setError("roleId is empty"); |
| 113 | return false; | 108 | return false; |
| 114 | } | 109 | } |
| 115 | if (TextUtils.isEmpty(extra)) { | 110 | if (TextUtils.isEmpty(extra)) { |
| 116 | etExtra.setError("extra is empty"); | 111 | etExtra.setError("extra is empty"); |
| 117 | return false; | 112 | return false; |
| 118 | } | 113 | } |
| 119 | if (TextUtils.isEmpty(amount)) { | 114 | if (TextUtils.isEmpty(amount)) { |
| 120 | etAmount.setError("amount is empty"); | 115 | etAmount.setError("amount is empty"); |
| 121 | return false; | 116 | return false; |
| 122 | } | 117 | } |
| 123 | return true; | 118 | return true; |
| 124 | } | 119 | } |
| 125 | 120 | ||
| 126 | class EditTextWatcher implements TextWatcher { | 121 | class EditTextWatcher implements TextWatcher { |
| 127 | 122 | ||
| 128 | private TextInputLayout editText; | 123 | private TextInputLayout editText; |
| 129 | 124 | ||
| 130 | public EditTextWatcher(TextInputLayout editText) { | 125 | public EditTextWatcher(TextInputLayout editText) { |
| 131 | this.editText = editText; | 126 | this.editText = editText; |
| 132 | } | 127 | } |
| 133 | 128 | ||
| 134 | @Override | 129 | @Override |
| 135 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { | 130 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { |
| 136 | 131 | ||
| 137 | } | 132 | } |
| 138 | 133 | ||
| 139 | @Override | 134 | @Override |
| 140 | public void onTextChanged(CharSequence s, int start, int before, int count) { | 135 | public void onTextChanged(CharSequence s, int start, int before, int count) { |
| 141 | editText.setError(null); | 136 | editText.setError(null); |
| 142 | } | 137 | } |
| 143 | 138 | ||
| 144 | @Override | 139 | @Override |
| 145 | public void afterTextChanged(Editable s) { | 140 | public void afterTextChanged(Editable s) { |
| 146 | 141 | ||
| 147 | } | 142 | } |
| 148 | } | 143 | } |
| 149 | } | 144 | } |
| 150 | 145 |
README.md
| 1 | # Gump SDK 4 for Android接入文档 | 1 | # Gump SDK 4 for Android接入文档 |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | V4.7.0 | 4 | V4.7.1 |
| 5 | 2019年02月21日 | 5 | 2019年03月19日 |
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | ## 版本概述 | 8 | ## 版本概述 |
| 9 | 9 | ||
| 10 | 此版本为使用AndroidStudio开发的版本,一改eclipse的工程依赖方式,使用aar的方式提供sdk接入包,除功能外,相对上一版本没有继承关系,请按此文档描述接入. | 10 | 此版本为使用AndroidStudio开发的版本,一改eclipse的工程依赖方式,使用aar的方式提供sdk接入包,除功能外,相对上一版本没有继承关系,请按此文档描述接入. |
| 11 | 11 | ||
| 12 | 此SDK适用android4.0以上系统. | 12 | 此SDK适用android4.0以上系统. |
| 13 | 13 | ||
| 14 | ## 第一章 接入指南 | 14 | ## 第一章 接入指南 |
| 15 | ### 1.依赖导入 | 15 | ### 1.依赖导入 |
| 16 | 配置gradle,以下为必须项 | 16 | 配置gradle,以下为必须项 |
| 17 | 17 | ||
| 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.7.0' | 24 | implementation 'com.gumptech.sdk:GameSDK:4.7.1' |
| 25 | 25 | ||
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | 28 | ||
| 29 | ### 2.修改AndroidManifest.xml文件 | 29 | ### 2.修改AndroidManifest.xml文件 |
| 30 | 首先添加必要的权限,如下所示: | 30 | 首先添加必要的权限,如下所示: |
| 31 | 31 | ||
| 32 | <uses-permission android:name="android.permission.INTERNET" /> | 32 | <uses-permission android:name="android.permission.INTERNET" /> |
| 33 | <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> | 33 | <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> |
| 34 | <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> | 34 | <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> |
| 35 | <!-- VERY IMPORTANT! Don't forget this permission, or in-app billing won't work. --> | 35 | <!-- VERY IMPORTANT! Don't forget this permission, or in-app billing won't work. --> |
| 36 | <uses-permission android:name="com.android.vending.BILLING" /> | 36 | <uses-permission android:name="com.android.vending.BILLING" /> |
| 37 | 37 | ||
| 38 | 其次注册相应的Activity,具体如下: | 38 | 其次注册相应的Activity,具体如下: |
| 39 | 39 | ||
| 40 | 40 | ||
| 41 | <activity | 41 | <activity |
| 42 | android:name="com.gumptech.sdk.PaymentActivity" | 42 | android:name="com.gumptech.sdk.PaymentActivity" |
| 43 | android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout" | 43 | android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout" |
| 44 | android:launchMode="singleTask" | 44 | android:launchMode="singleTask" |
| 45 | android:screenOrientation="behind" | 45 | android:screenOrientation="behind" |
| 46 | android:theme="@style/Theme.Translucent" > | 46 | android:theme="@style/Theme.Translucent" > |
| 47 | <intent-filter> | 47 | <intent-filter> |
| 48 | <category android:name="android.intent.category.DEFAULT" /> | 48 | <category android:name="android.intent.category.DEFAULT" /> |
| 49 | <action android:name="android.intent.action.VIEW" /> | 49 | <action android:name="android.intent.action.VIEW" /> |
| 50 | <category android:name="android.intent.category.BROWSABLE" /> | 50 | <category android:name="android.intent.category.BROWSABLE" /> |
| 51 | <data | 51 | <data |
| 52 | android:host="com.gump.sdk" | 52 | android:host="com.gump.sdk" |
| 53 | android:scheme="gump+游戏的appId" /> | 53 | android:scheme="gump+游戏的appId" /> |
| 54 | </intent-filter> | 54 | </intent-filter> |
| 55 | </activity> | 55 | </activity> |
| 56 | 56 | ||
| 57 | ### 3.向Gump平台索要游戏ID(AppID),完成代码接入 | 57 | ### 3.向Gump平台索要游戏ID(AppID),完成代码接入 |
| 58 | 正式开始接入逻辑代码前,先介绍下一些附加设置,以方便代码接入 | 58 | 正式开始接入逻辑代码前,先介绍下一些附加设置,以方便代码接入 |
| 59 | 59 | ||
| 60 | *是否打印debug日志 | 60 | *是否打印debug日志 |
| 61 | 61 | ||
| 62 | GumpSDK.getSettings().enableDebugLogging(true); | 62 | GumpSDK.getSettings().enableDebugLogging(true); |
| 63 | 63 | ||
| 64 | *设置需要启用的第三方登录,参数可选类型见第二章:[第三方登录平台](http://repository.gumptech.com:81/document/gamesdk4-android/blob/master/IntegrationGuide.md#1-third_plat) 字段说明 | 64 | *设置需要启用的第三方登录,参数可选类型见第二章:[第三方登录平台](http://repository.gumptech.com:81/document/gamesdk4-android/blob/master/IntegrationGuide.md#1-third_plat) 字段说明 |
| 65 | 65 | ||
| 66 | GumpSDK.getSettings().requestThirdSupport(SDKSettings.THIRD_SUPPORT_*); | 66 | GumpSDK.getSettings().requestThirdSupport(SDKSettings.THIRD_SUPPORT_*); |
| 67 | 67 | ||
| 68 | *若要使用V4版支付请设置 | 68 | *若要使用V4版支付请设置 |
| 69 | 69 | ||
| 70 | GumpSDK.getSettings().setPaymentVersion(PaymentVersion.V4); | 70 | GumpSDK.getSettings().setPaymentVersion(PaymentVersion.V4); |
| 71 | 71 | ||
| 72 | #### 1.调用GumpSDK前需要执行初始化。 | 72 | #### 1.调用GumpSDK前需要执行初始化。 |
| 73 | 73 | ||
| 74 | 若不需要分渠道 | 74 | 若不需要分渠道 |
| 75 | 75 | ||
| 76 | GumpSDK.init(Context,Appid, Appkey,InitializeCallback); | 76 | GumpSDK.init(Context,Appid, Appkey,InitializeCallback); |
| 77 | 如果需要定义渠道,必须使用如下方法 | 77 | 如果需要定义渠道,必须使用如下方法 |
| 78 | 78 | ||
| 79 | GumpSDK.init(Context,Appid, Appkey,ChannelId,InitializeCallback); | 79 | GumpSDK.init(Context,Appid, Appkey,ChannelId,InitializeCallback); |
| 80 | 80 | ||
| 81 | InitializeCallback为初始化回调接口,此接口只有一个回调方法initComplete(int result) result标识是否初始化成功,当result等于GumpSDK.CODE.OK时为成功,其他为失败 | 81 | InitializeCallback为初始化回调接口,此接口只有一个回调方法initComplete(int result) result标识是否初始化成功,当result等于GumpSDK.CODE.OK时为成功,其他为失败 |
| 82 | 82 | ||
| 83 | #### 2.调用GumpSDK的开始方法,将执行登录流程,需要一个Activity实例作参数 | 83 | #### 2.调用GumpSDK的开始方法,将执行登录流程,需要一个Activity实例作参数 |
| 84 | 84 | ||
| 85 | GumpSDK.start(Activity); | 85 | GumpSDK.start(Activity); |
| 86 | 在此之前,开发者需要注册用户状态监听以接受用户的登录/登出通知,通常如下: | 86 | 在此之前,开发者需要注册用户状态监听以接受用户的登录/登出通知,通常如下: |
| 87 | 87 | ||
| 88 | GumpSDK.setUserStateListener(new LoginStateListener() { | 88 | GumpSDK.setUserStateListener(new LoginStateListener() { |
| 89 | @Override | 89 | @Override |
| 90 | public void onLoginSuccess(GumpUser gumpUser) { | 90 | public void onLoginSuccess(GumpUser gumpUser) { |
| 91 | //登录成功,用户信息包含在GumpUser对象里 | 91 | //登录成功,用户信息包含在GumpUser对象里 |
| 92 | } | 92 | } |
| 93 | 93 | ||
| 94 | @Override | 94 | @Override |
| 95 | public void onLoginFailed(int code, String msg) { | 95 | public void onLoginFailed(int code, String msg) { |
| 96 | //登录出错,根据错误码和信息判断错误类型 | 96 | //登录出错,根据错误码和信息判断错误类型 |
| 97 | Toast.makeText(MainActivity.this, "Login failed:code="+code+",message="+msg, Toast.LENGTH_SHORT).show(); | 97 | Toast.makeText(MainActivity.this, "Login failed:code="+code+",message="+msg, Toast.LENGTH_SHORT).show(); |
| 98 | } | 98 | } |
| 99 | 99 | ||
| 100 | @Override | 100 | @Override |
| 101 | public void onLoginCanceled() { | 101 | public void onLoginCanceled() { |
| 102 | //用户取消登录 | 102 | //用户取消登录 |
| 103 | Toast.makeText(MainActivity.this, "operate be canceled", Toast.LENGTH_SHORT).show(); | 103 | Toast.makeText(MainActivity.this, "operate be canceled", Toast.LENGTH_SHORT).show(); |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | @Override | 106 | @Override |
| 107 | public void onLogout() { | 107 | public void onLogout() { |
| 108 | //用户登出 | 108 | //用户登出 |
| 109 | 109 | ||
| 110 | } | 110 | } |
| 111 | @Override | 111 | @Override |
| 112 | public void onPermissionDenied(String[] deniedPermissions) { | 112 | public void onPermissionDenied(String[] deniedPermissions) { |
| 113 | //用户未授予权限,参数为没有获取的权限 | 113 | //用户未授予权限,参数为没有获取的权限 |
| 114 | } | 114 | } |
| 115 | }); | 115 | }); |
| 116 | 116 | ||
| 117 | 如上成功登录后收到的GumpUser对象包含以下信息 | 117 | 如上成功登录后收到的GumpUser对象包含以下信息 |
| 118 | 118 | ||
| 119 | gumpUser.getUid();//获取用户的userid,此Id标识唯一用户! | 119 | gumpUser.getUid();//获取用户的userid,此Id标识唯一用户! |
| 120 | gumpUser.getAccountType();//用户类型,此类型数据可从GumpPreference常量获取 | 120 | gumpUser.getAccountType();//用户类型,此类型数据可从GumpPreference常量获取 |
| 121 | gumpUser.getSessionKey();//登录的sessionKey对象,获取sessionKey字符串请使用此对象的getToken()方法 | 121 | gumpUser.getSessionKey();//登录的sessionKey对象,获取sessionKey字符串请使用此对象的getToken()方法 |
| 122 | 122 | ||
| 123 | #### 3.支付功能 | 123 | #### 3.支付功能 |
| 124 | 调用支付前需先获取支付状态,根据状态调用支付方法 | 124 | 调用支付前需先获取支付状态,根据状态调用支付方法 |
| 125 | 125 | ||
| 126 | GumpSDK.shouldUseCoPay(Activity, serverId, roleId, new ResultCallback() { | 126 | GumpSDK.shouldUseCoPay(Activity, serverId, roleId, new ResultCallback() { |
| 127 | @Override | 127 | @Override |
| 128 | public void onResult(boolean result) { | 128 | public void onResult(boolean result) { |
| 129 | if(result){ | 129 | if(result){ |
| 130 | //调用GumpSDK.iap | 130 | //调用GumpSDK.iap |
| 131 | }else{ | 131 | }else{ |
| 132 | //调用GumpSDK.pay | 132 | //调用GumpSDK.pay |
| 133 | } | 133 | } |
| 134 | } | 134 | } |
| 135 | }); | 135 | }); |
| 136 | 136 | ||
| 137 | 1)调用GumpSDK.pay | 137 | 1)调用GumpSDK.pay |
| 138 | 138 | ||
| 139 | Bundle payInfo = new Bundle(); | 139 | Bundle payInfo = new Bundle(); |
| 140 | payInfo.putString("product", "元宝"); | 140 | payInfo.putString("product", "元宝"); |
| 141 | payInfo.putFloat("amount", 40.0f); | 141 | payInfo.putFloat("amount", 40.0f); |
| 142 | payInfo.putString("extraInfo", "This is demo!"); | 142 | payInfo.putString("extraInfo", "This is demo!"); |
| 143 | payInfo.putString("serverId", "B4003"); | 143 | payInfo.putString("serverId", "B4003"); |
| 144 | payInfo.putString("roleId", "10010"); | 144 | payInfo.putString("roleId", "10010"); |
| 145 | payInfo.putString("currency","currency"); | 145 | payInfo.putString("currency","currency"); |
| 146 | GumpSDK.pay(MainActivity.this, payInfo,PurchaseCallback); | 146 | GumpSDK.pay(MainActivity.this, payInfo,PurchaseCallback); |
| 147 | 调用pay方法时,必须穿入一个bundle对象,包含如上字段,所有字段必须全部包含 | 147 | 调用pay方法时,必须穿入一个bundle对象,包含如上字段,所有字段必须全部包含 |
| 148 | 148 | ||
| 149 | 149 | ||
| 150 | 2)IAP支付 | 150 | 2)IAP支付 |
| 151 | 151 | ||
| 152 | Bundle payInfo = new Bundle(); | 152 | Bundle payInfo = new Bundle(); |
| 153 | payInfo.putString("product", "gp_skuId"); | 153 | payInfo.putString("product", "gp_skuId"); |
| 154 | payInfo.putFloat("amount", 0.1f); | 154 | payInfo.putFloat("amount", 0.1f); |
| 155 | payInfo.putString("extraInfo", "This is demo!"); | 155 | payInfo.putString("extraInfo", "This is demo!"); |
| 156 | payInfo.putString("serverId", "100"); | 156 | payInfo.putString("serverId", "100"); |
| 157 | payInfo.putString("roleId","100123"); | 157 | payInfo.putString("roleId","100123"); |
| 158 | GumpSDK.iap(MainActivity.this, payInfo, PurchaseCallback); | 158 | GumpSDK.iap(MainActivity.this, payInfo, PurchaseCallback); |
| 159 | 159 | ||
| 160 | 3)PurchaseCallback为支付状态回调接口,此接口含有3个方法 | 160 | 3)PurchaseCallback为支付状态回调接口,此接口含有3个方法 |
| 161 | 161 | ||
| 162 | @Override | 162 | @Override |
| 163 | public void onPurchaseCompleted(PurchaseResult result) { | 163 | public void onPurchaseCompleted(PurchaseResult result) { |
| 164 | Log.i(TAG,"purchase completed"); | 164 | Log.i(TAG,"purchase completed"); |
| 165 | } | 165 | } |
| 166 | 166 | ||
| 167 | @Override | 167 | @Override |
| 168 | public void onPurchaseError(int code, String msg) { | 168 | public void onPurchaseError(int code, String msg) { |
| 169 | Log.i(TAG,"purchase error"); | 169 | Log.i(TAG,"purchase error"); |
| 170 | } | 170 | } |
| 171 | 171 | ||
| 172 | @Override | 172 | @Override |
| 173 | public void onPurchaseCanceled() { | 173 | public void onPurchaseCanceled() { |
| 174 | Log.i(TAG,"purchase canceled"); | 174 | Log.i(TAG,"purchase canceled"); |
| 175 | } | 175 | } |
| 176 | 176 | ||
| 177 | #### 4.注销登录 | 177 | #### 4.注销登录 |
| 178 | 178 | ||
| 179 | GumpSDK.logout(Activity); | 179 | GumpSDK.logout(Activity); |
| 180 | 当此方法调用后,用户退出登录,并会通过LoginStateListener接口通知调用程序!为了便于用户切换登录账户,请在游戏内提供用户注销的触发按钮 | 180 | 当此方法调用后,用户退出登录,并会通过LoginStateListener接口通知调用程序!为了便于用户切换登录账户,请在游戏内提供用户注销的触发按钮 |
| 181 | #### 5.运营开关接口,若需要接入,会有我方运营人员提出需求,否则不需要接入(若对此接口不知所云,即可认为不需要接入,请自行忽略) | 181 | #### 5.运营开关接口,若需要接入,会有我方运营人员提出需求,否则不需要接入(若对此接口不知所云,即可认为不需要接入,请自行忽略) |
| 182 | 182 | ||
| 183 | GumpSDK.checkRisk(this, new ResultCallback() { | 183 | GumpSDK.checkRisk(this, new ResultCallback() { |
| 184 | @Override | 184 | @Override |
| 185 | public void onResult(boolean result) { | 185 | public void onResult(boolean result) { |
| 186 | Log.i(TAG,result?"There is some risks":"Nothing is risk"); | 186 | Log.i(TAG,result?"There is some risks":"Nothing is risk"); |
| 187 | } | 187 | } |
| 188 | }); | 188 | }); |
| 189 | 189 | ||
| 190 | ## 第二章 常量字段与代码 | 190 | ## 第二章 常量字段与代码 |
| 191 | ### 1.第三方登录平台(third_plat) | 191 | ### 1.第三方登录平台(third_plat) |
| 192 | | 常量字段 | 说明 | | 192 | | 常量字段 | 说明 | |
| 193 | |--------------------------------|--------------| | 193 | |--------------------------------|--------------| |
| 194 | |SDKSettings.THIRD_SUPPORT_FB | Facebook登录 | | 194 | |SDKSettings.THIRD_SUPPORT_FB | Facebook登录 | |
| 195 | |SDKSettings.THIRD_SUPPORT_GOOGLE| Google登录 | | 195 | |SDKSettings.THIRD_SUPPORT_GOOGLE| Google登录 | |
| 196 | |SDKSettings.THIRD_SUPPORT_LINE | Line登录 | | 196 | |SDKSettings.THIRD_SUPPORT_LINE | Line登录 | |
| 197 | 197 | ||
| 198 | ### 2.登录账户类型 | 198 | ### 2.登录账户类型 |
| 199 | | 常量字段 | 说明 | | 199 | | 常量字段 | 说明 | |
| 200 | |-------------------------------------|--------------| | 200 | |-------------------------------------|--------------| |
| 201 | |GumpPreference.ACCOUNT_TYPE_FB | Facebook用户 | | 201 | |GumpPreference.ACCOUNT_TYPE_FB | Facebook用户 | |
| 202 | |GumpPreference.ACCOUNT_TYPE_REG | Gump注册用户 | | 202 | |GumpPreference.ACCOUNT_TYPE_REG | Gump注册用户 | |
| 203 | |GumpPreference.ACCOUNT_TYPE_QUICK_REG| 游客 | | 203 | |GumpPreference.ACCOUNT_TYPE_QUICK_REG| 游客 | |
| 204 | |GumpPreference.ACCOUNT_TYPE_GOOGLE | Google用户 | | 204 | |GumpPreference.ACCOUNT_TYPE_GOOGLE | Google用户 | |
| 205 | |GumpPreference.ACCOUNT_TYPE_LINE | Line用户 | | 205 | |GumpPreference.ACCOUNT_TYPE_LINE | Line用户 | |
| 206 | 206 | ||
| 207 | 207 | ||
| 208 | 208 | ||
| 209 | ## 第三章 常见问题 | 209 | ## 第三章 常见问题 |
| 210 | ### 问题1: 如何避免混淆对SDK的影响? | 210 | ### 问题1: 如何避免混淆对SDK的影响? |
| 211 | 解答:有些开发者对接入了SDK的程序进行混淆时,有可能会覆盖某些java | 211 | 解答:有些开发者对接入了SDK的程序进行混淆时,有可能会覆盖某些java |
| 212 | 类,导致SDK无法正常工作,解决方法如下: | 212 | 类,导致SDK无法正常工作,解决方法如下: |
| 213 | Ø 请开发者在混淆配置文件proguard.cfg或proguard-project.txt的最后加上 | 213 | Ø 请开发者在混淆配置文件proguard.cfg或proguard-project.txt的最后加上 |
| 214 | 214 | ||
| 215 | -keepattributes *Annotation*,InnerClasses,SourceFile,LineNumberTable | 215 | -keepattributes *Annotation*,InnerClasses,SourceFile,LineNumberTable |
| 216 | -keep public class * extends android.app.Service | 216 | -keep public class * extends android.app.Service |
| 217 | -keep public class com.google.vending.licensing.ILicensingService | 217 | -keep public class com.google.vending.licensing.ILicensingService |
| 218 | -keep public class com.android.vending.licensing.ILicensingService | 218 | -keep public class com.android.vending.licensing.ILicensingService |
| 219 | -keep class com.gumptech.sdk.view.* {*;} | 219 | -keep class com.gumptech.sdk.view.* {*;} |
| 220 | -keep class com.gumptech.sdk.web.* {*;} | 220 | -keep class com.gumptech.sdk.web.* {*;} |
| 221 | -keep class com.gumptech.sdk.bridge.impl.*{*;} | 221 | -keep class com.gumptech.sdk.bridge.impl.*{*;} |
| 222 | 222 | ||
| 223 | 223 | ||
| 224 | 使得混淆的时候不会影响SDK的命名空间。 | 224 | 使得混淆的时候不会影响SDK的命名空间。 |