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