Commit 020faf4c865b2d997dbe662b317da24b52143c54

Authored by 赵康
1 parent dc26b0ad68
Exists in master

文档更新

Showing 2 changed files with 22 additions and 18 deletions Inline Diff

1 # Gump SDK 5 for Android接入文档 1 # Gump SDK 5 for Android接入文档
2 2
3 V5.2.2 3 V5
4 2019年06月06日 4 2019年07月16日
5 5
6 ## 版本概述 6 ## 版本概述
7 7
8 此版本为使用AndroidStudio开发的版本,使用aar在线依赖的方式提供sdk接入包,相对上一版本没有任何继承关系,请按此文档描述接入. 8 此版本为使用AndroidStudio开发的版本,使用aar在线依赖的方式提供sdk接入包,相对上一版本没有任何继承关系,请按此文档描述接入.
9 9
10 此SDK适用android4.0以上系统. 10 此SDK适用android4.0以上系统.
11 11
12 本SDK分为两个部分:登录和支付,请按需引用依赖包. 12 本SDK分为两个部分:登录和支付,请按需引用依赖包.
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 //登录功能依赖 24 //登录功能依赖
25 implementation 'com.gump:Passport:5.2.2' 25 implementation 'com.gump:Passport:5.2.2'
26 //支付功能依赖 26 //支付功能依赖
27 implementation 'com.gump:Payment:5.2.2' 27 implementation 'com.gump:Payment:5.2.3'
28 } 28 }
29 29
30 ### 2.修改AndroidManifest.xml文件 30 ### 2.修改AndroidManifest.xml文件
31 首先添加必要的权限,如下所示: 31 首先添加必要的权限,如下所示:
32 32
33 <uses-permission android:name="android.permission.INTERNET" /> 33 <uses-permission android:name="android.permission.INTERNET" />
34 <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> 34 <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
35 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 35 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
36 <!-- VERY IMPORTANT! Don't forget this permission, or in-app billing won't work. --> 36 <!-- VERY IMPORTANT! Don't forget this permission, or in-app billing won't work. -->
37 <uses-permission android:name="com.android.vending.BILLING" /> 37 <uses-permission android:name="com.android.vending.BILLING" />
38 38
39 创建一个strings 配置如下 39 创建一个strings 配置如下
40 40
41 <string name="app_id">your_play_games_app_id</string> 41 <string name="app_id">your_play_games_app_id</string>
42 42
43 增加play games的meta-data配置 43 增加play games的meta-data配置
44 44
45 <meta-data 45 <meta-data
46 android:name="com.google.android.gms.games.APP_ID" 46 android:name="com.google.android.gms.games.APP_ID"
47 android:value="@string/app_id"/> 47 android:value="@string/app_id"/>
48 <meta-data 48 <meta-data
49 android:name="com.google.android.gms.version" 49 android:name="com.google.android.gms.version"
50 android:value="@integer/google_play_services_version"/> 50 android:value="@integer/google_play_services_version"/>
51 51
52 ### 3.1 初始化与配置 52 ### 3.1 初始化与配置
53 53
54 *若要使用V4版支付请设置 54 *若要使用V4版支付请设置
55 55
56 SDKAgent.getSettings().setPaymentVersion(PaymentVersion.V4); 56 SDKAgent.getSettings().setPaymentVersion(PaymentVersion.V4);
57 57
58 *执行初始化 58 *执行初始化
59 59
60 SDKAgent.init(Context,Appid,ChannelId); 60 SDKAgent.init(Context,Appid,ChannelId);
61 61
62 ### 3.2 登录接入 62 ### 3.2 登录接入
63 AndroidManifest.xml配置: 63 AndroidManifest.xml配置:
64 64
65 <activity 65 <activity
66 android:name="com.gump.gpassport.GumpLoginActivity" 66 android:name="com.gump.gpassport.GumpLoginActivity"
67 android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout" 67 android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout"
68 android:launchMode="singleTask" 68 android:launchMode="singleTask"
69 android:screenOrientation="behind" 69 android:screenOrientation="behind"
70 android:theme="@style/Theme.AppCompat.Light.NoActionBar"/> 70 android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>
71 构建Passport实例 71 构建Passport实例
72 72
73 passport = new Passport.Builder().context(Context).setListener(StateListener).build(); 73 passport = new Passport.Builder().context(Context).setListener(StateListener).build();
74 74
75 其中StateListener为登录状态监听接口,需要实现如下方法 75 其中StateListener为登录状态监听接口,需要实现如下方法
76 76
77 //成功回调,成功事件类型由action枚举对象标识,player是成功返回的玩家对象 77 //成功回调,成功事件类型由action枚举对象标识,player是成功返回的玩家对象
78 void onActionSucced(Actions action, GamePlayer player) 78 void onActionSucced(Actions action, GamePlayer player)
79 //失败回调 79 //失败回调
80 void onActionFailured() 80 void onActionFailured()
81 81
82 Actinos枚举: 82 Actinos枚举:
83 83
84 SIGN 登录 84 SIGN 登录
85 SWITCH_PENDING 切换PlayGame账号,需重启游戏 85 SWITCH_PENDING 切换PlayGame账号,需重启游戏
86 SWITCH 已切换甘普账号,需重新加载用户角色信息 86 SWITCH 已切换甘普账号,需重新加载用户角色信息
87 87
88 接下来,添加生命周期处理方法 88 接下来,添加生命周期处理方法
89 89
90 @Override 90 @Override
91 protected void onResume() { 91 protected void onResume() {
92 super.onResume(); 92 super.onResume();
93 passport.onResume(); 93 passport.onResume();
94 } 94 }
95 95
96 处理结果返回 96 处理结果返回
97 97
98 @Override 98 @Override
99 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 99 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
100 if (!passport.onActivityResult(requestCode, resultCode, data)) 100 if (!passport.onActivityResult(requestCode, resultCode, data))
101 super.onActivityResult(requestCode, resultCode, data); 101 super.onActivityResult(requestCode, resultCode, data);
102 } 102 }
103 103
104 ### 3.3 账号联动 104 ### 3.3 账号联动
105 105
106 passport.link(Activity); 106 passport.link(Activity);
107 107
108 ### 3.4 账号切换 108 ### 3.4 账号切换
109 切换到PlayGame账号 109 切换到PlayGame账号
110 110
111 passport.switchAccount(); 111 passport.switchAccount();
112 112
113 113
114 ### 3.5 支付接入 114 ### 3.5 支付接入
115 注册相应的Activity,具体如下: 115 注册相应的Activity,具体如下:
116 116
117 <activity 117 <activity
118 android:name="com.gumptech.sdk.PaymentActivity" 118 android:name="com.gump.payment.PaymentActivity"
119 android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout" 119 android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout"
120 android:launchMode="singleTask" 120 android:screenOrientation="behind"
121 android:screenOrientation="behind" 121 android:launchMode="singleTask"
122 android:theme="@android:style/Theme.Translucent.NoTitleBar" > 122 android:theme="@style/Theme.Translucent">
123 <intent-filter> 123 <intent-filter>
124 <category android:name="android.intent.category.DEFAULT" /> 124 <action android:name="android.intent.action.VIEW"/>
125 <action android:name="android.intent.action.VIEW" /> 125
126 <category android:name="android.intent.category.BROWSABLE" /> 126 <category android:name="android.intent.category.DEFAULT"/>
127 <data 127
128 android:host="com.gump.sdk" 128 <category android:name="android.intent.category.BROWSABLE"/>
129 android:scheme="gump+游戏的appId" /> 129
130 </intent-filter> 130 <data
131 </activity> 131 android:host="com.gump.sdk"
132 android:scheme="gump+游戏的appId"/>
133 </intent-filter>
134 </activity>
135
132 136
133 1)判断是否使用三方支付 137 1)判断是否使用三方支付
134 138
135 Payment.shouldUseCoPay(this, serverId, roleId, new ResultCallback() { 139 Payment.shouldUseCoPay(this, serverId, roleId, new ResultCallback() {
136 @Override 140 @Override
137 public void onResult(boolean isRisk) { 141 public void onResult(boolean isRisk) {
138 //isRisk==true时使用IAB支付,isRisk==false时使用三方支付 142 //isRisk==true时使用IAB支付,isRisk==false时使用三方支付
139 } 143 }
140 }); 144 });
141 145
142 2)三方支付调用 146 2)三方支付调用
143 147
144 Bundle payInfo = new Bundle(); 148 Bundle payInfo = new Bundle();
145 payInfo.putString("product", "wa2"); 149 payInfo.putString("product", "wa2");
146 payInfo.putFloat("amount", 0.1f); 150 payInfo.putFloat("amount", 0.1f);
147 payInfo.putString("extraInfo", "This is demo!"); 151 payInfo.putString("extraInfo", "This is demo!");
148 payInfo.putString("serverId", "100"); 152 payInfo.putString("serverId", "100");
149 payInfo.putString("roleId", "41080"); 153 payInfo.putString("roleId", "41080");
150 Payment.pay(Activity, payInfo, PurchaseCallback); 154 Payment.pay(Activity, payInfo, PurchaseCallback);
151 155
152 3)Google IAB支付调用 156 3)Google IAB支付调用
153 157
154 Bundle payInfo = new Bundle(); 158 Bundle payInfo = new Bundle();
155 payInfo.putString("product", "180010"); 159 payInfo.putString("product", "180010");
156 payInfo.putFloat("amount", 0.1f); 160 payInfo.putFloat("amount", 0.1f);
157 payInfo.putString("extraInfo", "This is demo!"); 161 payInfo.putString("extraInfo", "This is demo!");
158 payInfo.putString("serverId", "100"); 162 payInfo.putString("serverId", "100");
159 payInfo.putString("roleId", "41080"); 163 payInfo.putString("roleId", "41080");
160 Payment.launchIAP(Activity, payInfo, PurchaseCallback); 164 Payment.launchIAP(Activity, payInfo, PurchaseCallback);
161 165
162 PurchaseCallback为支付状态回调接口,此接口含有3个方法 166 PurchaseCallback为支付状态回调接口,此接口含有3个方法
163 167
164 @Override 168 @Override
165 public void onPurchaseCompleted(PurchaseResult result) { 169 public void onPurchaseCompleted(PurchaseResult result) {
166 Log.i(TAG,"purchase completed"); 170 Log.i(TAG,"purchase completed");
167 } 171 }
168 172
169 @Override 173 @Override
170 public void onPurchaseError(int code, String msg) { 174 public void onPurchaseError(int code, String msg) {
171 Log.i(TAG,"purchase error"); 175 Log.i(TAG,"purchase error");
172 } 176 }
173 177
174 @Override 178 @Override
175 public void onPurchaseCanceled() { 179 public void onPurchaseCanceled() {
176 Log.i(TAG,"purchase canceled"); 180 Log.i(TAG,"purchase canceled");
177 } 181 }
178 182
179 ## 第二章 常见问题 183 ## 第二章 常见问题
180 ### 问题1: 如何避免混淆对SDK的影响? 184 ### 问题1: 如何避免混淆对SDK的影响?
181 解答:有些开发者对接入了SDK的程序进行混淆时,有可能会覆盖某些java 185 解答:有些开发者对接入了SDK的程序进行混淆时,有可能会覆盖某些java
182 类,导致SDK无法正常工作,解决方法如下: 186 类,导致SDK无法正常工作,解决方法如下:
183 Ø 请开发者在混淆配置文件proguard.cfg或proguard-project.txt的最后加上 187 Ø 请开发者在混淆配置文件proguard.cfg或proguard-project.txt的最后加上
184 188
185 -keep class com.gump.payment.web.* {*;} 189 -keep class com.gump.payment.web.* {*;}
186 190
187 使得混淆的时候不会影响SDK的命名空间。 191 使得混淆的时候不会影响SDK的命名空间。
1 apply plugin: 'com.android.application' 1 apply plugin: 'com.android.application'
2 2
3 3
4 android { 4 android {
5 compileSdkVersion 27 5 compileSdkVersion 27
6 defaultConfig { 6 defaultConfig {
7 applicationId "com.gump.passport.demo" 7 applicationId "com.gump.passport.demo"
8 minSdkVersion 15 8 minSdkVersion 15
9 targetSdkVersion 27 9 targetSdkVersion 27
10 versionCode 9 10 versionCode 9
11 versionName "1.0.9" 11 versionName "1.0.9"
12 testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 vectorDrawables.useSupportLibrary = true 13 vectorDrawables.useSupportLibrary = true
14 } 14 }
15 buildTypes { 15 buildTypes {
16 release { 16 release {
17 minifyEnabled false 17 minifyEnabled false
18 proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 } 19 }
20 } 20 }
21 21
22 applicationVariants.all { 22 applicationVariants.all {
23 variant -> 23 variant ->
24 variant.outputs.all { 24 variant.outputs.all {
25 outputFileName = "SDKDemo-" + variant.name + defaultConfig.versionName + ".apk" 25 outputFileName = "SDKDemo-" + variant.name + defaultConfig.versionName + ".apk"
26 } 26 }
27 } 27 }
28 28
29 lintOptions { 29 lintOptions {
30 abortOnError false 30 abortOnError false
31 } 31 }
32 } 32 }
33 33
34 dependencies { 34 dependencies {
35 implementation fileTree(dir: 'libs', include: ['*.jar']) 35 implementation fileTree(dir: 'libs', include: ['*.jar'])
36 implementation 'com.android.support:appcompat-v7:27.1.1' 36 implementation 'com.android.support:appcompat-v7:27.1.1'
37 implementation 'com.android.support:support-v4:27.1.1' 37 implementation 'com.android.support:support-v4:27.1.1'
38 implementation 'com.android.support:support-vector-drawable:27.1.1' 38 implementation 'com.android.support:support-vector-drawable:27.1.1'
39 testImplementation 'junit:junit:4.12' 39 testImplementation 'junit:junit:4.12'
40 40
41 //基础功能依赖,必须 41 //基础功能依赖,必须
42 // implementation 'com.gump:base:5.1.1' 42 // implementation 'com.gump:base:5.1.1'
43 // implementation project(':base') 43 // implementation project(':base')
44 // 登录功能依赖 44 // 登录功能依赖
45 implementation 'com.gump:Passport:5.2.2' 45 implementation 'com.gump:Passport:5.2.2'
46 // implementation project(':passport') 46 // implementation project(':passport')
47 //支付功能依赖 47 //支付功能依赖
48 implementation 'com.gump:Payment:5.2.2' 48 implementation 'com.gump:Payment:5.2.3'
49 // implementation project(':payment') 49 // implementation project(':payment')
50 } 50 }
51 51