Commit 4020ad46e5b3577e15ece630760f2de34677b601
1 parent
05bcef797c
Exists in
master
version:4.2.0:增加Google登录
Showing 1 changed file with 1 additions and 1 deletions Inline Diff
IntegrationGuide.md
1 | # Gump SDK 4 for Android接入文档 | 1 | # Gump SDK 4 in new domain for Android接入文档 |
2 | 2 | ||
3 | V4.2.0 | 3 | V4.2.0 |
4 | 2017年4月26日 | 4 | 2017年4月26日 |
5 | 5 | ||
6 | ## 版本概述 | 6 | ## 版本概述 |
7 | 7 | ||
8 | 此版本为使用AndroidStudio开发的第一个版本,一改eclipse的工程依赖方式,使用aar的方式提供sdk接入包,除功能外,相对上一版本没有继承关系,请按此文档描述接入. | 8 | 此版本为使用AndroidStudio开发的第一个版本,一改eclipse的工程依赖方式,使用aar的方式提供sdk接入包,除功能外,相对上一版本没有继承关系,请按此文档描述接入. |
9 | 9 | ||
10 | 此SDK适用android2.3以上系统. | 10 | 此SDK适用android2.3以上系统. |
11 | 11 | ||
12 | ## 第一章 接入指南 | 12 | ## 第一章 接入指南 |
13 | ### 1.依赖导入 | 13 | ### 1.依赖导入 |
14 | 将aar添加到libs目录下,然后配置gradle | 14 | 将aar添加到libs目录下,然后配置gradle |
15 | 以下为必须项 | 15 | 以下为必须项 |
16 | 16 | ||
17 | repositories{ | 17 | repositories{ |
18 | flatDir{ | 18 | flatDir{ |
19 | dirs 'libs' | 19 | dirs 'libs' |
20 | } | 20 | } |
21 | } | 21 | } |
22 | dependencies { | 22 | dependencies { |
23 | compile(name:'GameSDK-releaseXXX',ext:'aar') | 23 | compile(name:'GameSDK-releaseXXX',ext:'aar') |
24 | } | 24 | } |
25 | 25 | ||
26 | 26 | ||
27 | 可选接入vk登录时,需要导入vkLibrary工程,并配置模块依赖,如下 | 27 | 可选接入vk登录时,需要导入vkLibrary工程,并配置模块依赖,如下 |
28 | 28 | ||
29 | compile project(':vksdk_library') | 29 | compile project(':vksdk_library') |
30 | 30 | ||
31 | ### 2.修改AndroidManifest.xml文件 | 31 | ### 2.修改AndroidManifest.xml文件 |
32 | 首先添加必要的权限,如下所示: | 32 | 首先添加必要的权限,如下所示: |
33 | 33 | ||
34 | <uses-permission android:name="android.permission.INTERNET" /> | 34 | <uses-permission android:name="android.permission.INTERNET" /> |
35 | <uses-permission android:name="android.permission.READ_PHONE_STATE" /> | 35 | <uses-permission android:name="android.permission.READ_PHONE_STATE" /> |
36 | <uses-permission android:name="android.permission.BLUETOOTH" /> | 36 | <uses-permission android:name="android.permission.BLUETOOTH" /> |
37 | <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> | 37 | <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> |
38 | <uses-permission android:name="android.permission.WRITE_SETTINGS"/> | 38 | <uses-permission android:name="android.permission.WRITE_SETTINGS"/> |
39 | <uses-permission android:name="android.permission.GET_ACCOUNTS"/> | 39 | <uses-permission android:name="android.permission.GET_ACCOUNTS"/> |
40 | <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> | 40 | <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> |
41 | <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> | 41 | <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> |
42 | <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/> | 42 | <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/> |
43 | <uses-permission android:name="android.permission.SEND_SMS"/> | 43 | <uses-permission android:name="android.permission.SEND_SMS"/> |
44 | <!-- VERY IMPORTANT! Don't forget this permission, or in-app billing won't work. --> | 44 | <!-- VERY IMPORTANT! Don't forget this permission, or in-app billing won't work. --> |
45 | <uses-permission android:name="com.android.vending.BILLING" /> | 45 | <uses-permission android:name="com.android.vending.BILLING" /> |
46 | 46 | ||
47 | 其次注册相应的Activity,具体如下: | 47 | 其次注册相应的Activity,具体如下: |
48 | 48 | ||
49 | <activity | 49 | <activity |
50 | android:name="com.g.root.ContainerActivity" | 50 | android:name="com.g.root.ContainerActivity" |
51 | android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout" | 51 | android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout" |
52 | android:windowSoftInputMode="stateAlwaysHidden|adjustPan" | 52 | android:windowSoftInputMode="stateAlwaysHidden|adjustPan" |
53 | android:launchMode="singleTask" | 53 | android:launchMode="singleTask" |
54 | android:theme="@style/Theme.TransparentWin" > | 54 | android:theme="@style/Theme.TransparentWin" > |
55 | </activity> | 55 | </activity> |
56 | <activity | 56 | <activity |
57 | android:name="com.g.root.PaymentActivity" | 57 | android:name="com.g.root.PaymentActivity" |
58 | android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout" | 58 | android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout" |
59 | android:launchMode="singleTask" | 59 | android:launchMode="singleTask" |
60 | android:theme="@android:style/Theme.Translucent.NoTitleBar" > | 60 | android:theme="@android:style/Theme.Translucent.NoTitleBar" > |
61 | <intent-filter> | 61 | <intent-filter> |
62 | <category android:name="android.intent.category.DEFAULT" /> | 62 | <category android:name="android.intent.category.DEFAULT" /> |
63 | <action android:name="android.intent.action.VIEW" /> | 63 | <action android:name="android.intent.action.VIEW" /> |
64 | <category android:name="android.intent.category.BROWSABLE" /> | 64 | <category android:name="android.intent.category.BROWSABLE" /> |
65 | <data | 65 | <data |
66 | android:host="com.gump.sdk" | 66 | android:host="com.gump.sdk" |
67 | android:scheme="gump+游戏的appId" /> | 67 | android:scheme="gump+游戏的appId" /> |
68 | </intent-filter> | 68 | </intent-filter> |
69 | </activity> | 69 | </activity> |
70 | <activity | 70 | <activity |
71 | android:name="com.g.root.ExchangeWindow" | 71 | android:name="com.g.root.ExchangeWindow" |
72 | android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout" | 72 | android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout" |
73 | android:theme="@style/Theme.WinForExchange" > | 73 | android:theme="@style/Theme.WinForExchange" > |
74 | </activity> | 74 | </activity> |
75 | 75 | ||
76 | <service android:name="com.g.root.PushService" /> | 76 | <service android:name="com.g.root.PushService" /> |
77 | 77 | ||
78 | <!-- vk登录使用,若不接入vk,不需配置 --> | 78 | <!-- vk登录使用,若不接入vk,不需配置 --> |
79 | <activity android:name="com.vk.sdk.VKOpenAuthActivity" /> | 79 | <activity android:name="com.vk.sdk.VKOpenAuthActivity" /> |
80 | <activity | 80 | <activity |
81 | android:name="com.vk.sdk.VKServiceActivity" | 81 | android:name="com.vk.sdk.VKServiceActivity" |
82 | android:label="ServiceActivity" | 82 | android:label="ServiceActivity" |
83 | android:theme="@style/VK.Transparent" /> | 83 | android:theme="@style/VK.Transparent" /> |
84 | 84 | ||
85 | ### 3.向Gump平台索要游戏ID(AppID),完成代码接入 | 85 | ### 3.向Gump平台索要游戏ID(AppID),完成代码接入 |
86 | 正式开始接入逻辑代码前,先介绍下一些附加设置,以方便代码接入 | 86 | 正式开始接入逻辑代码前,先介绍下一些附加设置,以方便代码接入 |
87 | 87 | ||
88 | *是否打印debug日志 | 88 | *是否打印debug日志 |
89 | 89 | ||
90 | GumpSDK.getSettings().enableDebugLogging(true); | 90 | GumpSDK.getSettings().enableDebugLogging(true); |
91 | 91 | ||
92 | *Gump Logo隐藏 | 92 | *Gump Logo隐藏 |
93 | 93 | ||
94 | GumpSDK.getSettings().setLogoShow(false); | 94 | GumpSDK.getSettings().setLogoShow(false); |
95 | 95 | ||
96 | *横竖屏控制,默认为横屏,参数为false即为竖屏 | 96 | *横竖屏控制,默认为横屏,参数为false即为竖屏 |
97 | 97 | ||
98 | GumpSDK.getSettings().setScreenLandscape(true); | 98 | GumpSDK.getSettings().setScreenLandscape(true); |
99 | 99 | ||
100 | *设置是否启用Facebook登录和VK登录 | 100 | *设置是否启用Facebook登录和VK登录 |
101 | 101 | ||
102 | GumpSDK.getSettings().setFBEnable(true); | 102 | GumpSDK.getSettings().setFBEnable(true); |
103 | GumpSDK.getSettings().setVKEnable(true); | 103 | GumpSDK.getSettings().setVKEnable(true); |
104 | 104 | ||
105 | *若要使用V4版支付请设置 | 105 | *若要使用V4版支付请设置 |
106 | 106 | ||
107 | GumpSDK.getSettings().setPaymentVersion(PaymentVersion.V4); | 107 | GumpSDK.getSettings().setPaymentVersion(PaymentVersion.V4); |
108 | 108 | ||
109 | #### 1.调用GumpSDK前需要执行初始化。 | 109 | #### 1.调用GumpSDK前需要执行初始化。 |
110 | 110 | ||
111 | 若不需要分渠道 | 111 | 若不需要分渠道 |
112 | 112 | ||
113 | GumpSDK.init(Context,Appid, Appkey,InitializeCallback); | 113 | GumpSDK.init(Context,Appid, Appkey,InitializeCallback); |
114 | 如果需要定义渠道,必须使用如下方法 | 114 | 如果需要定义渠道,必须使用如下方法 |
115 | 115 | ||
116 | GumpSDK.init(Context,Appid, Appkey,ChannelId,InitializeCallback); | 116 | GumpSDK.init(Context,Appid, Appkey,ChannelId,InitializeCallback); |
117 | 117 | ||
118 | InitializeCallback为初始化回调接口,此接口只有一个回调方法initComplete(int result) result标识是否初始化成功,当result等于GumpSDK.CODE.OK时为成功,其他为失败 | 118 | InitializeCallback为初始化回调接口,此接口只有一个回调方法initComplete(int result) result标识是否初始化成功,当result等于GumpSDK.CODE.OK时为成功,其他为失败 |
119 | 119 | ||
120 | #### 2.调用GumpSDK的开始方法,将执行登录流程,需要一个Activity实例作参数 | 120 | #### 2.调用GumpSDK的开始方法,将执行登录流程,需要一个Activity实例作参数 |
121 | 121 | ||
122 | GumpSDK.start(Activity); | 122 | GumpSDK.start(Activity); |
123 | 在此之前,开发者需要注册用户状态监听以接受用户的登录/登出通知,通常如下: | 123 | 在此之前,开发者需要注册用户状态监听以接受用户的登录/登出通知,通常如下: |
124 | 124 | ||
125 | GumpSDK.setUserStateListener(new LoginStateListener() { | 125 | GumpSDK.setUserStateListener(new LoginStateListener() { |
126 | @Override | 126 | @Override |
127 | public void onLoginSuccess(GumpUser gumpUser) { | 127 | public void onLoginSuccess(GumpUser gumpUser) { |
128 | //登录成功,用户信息包含在GumpUser对象里 | 128 | //登录成功,用户信息包含在GumpUser对象里 |
129 | } | 129 | } |
130 | 130 | ||
131 | @Override | 131 | @Override |
132 | public void onLoginFailed(int code, String msg) { | 132 | public void onLoginFailed(int code, String msg) { |
133 | //登录出错,根据错误码和信息判断错误类型 | 133 | //登录出错,根据错误码和信息判断错误类型 |
134 | Toast.makeText(MainActivity.this, "Login failed:code="+code+",message="+msg, Toast.LENGTH_SHORT).show(); | 134 | Toast.makeText(MainActivity.this, "Login failed:code="+code+",message="+msg, Toast.LENGTH_SHORT).show(); |
135 | } | 135 | } |
136 | 136 | ||
137 | @Override | 137 | @Override |
138 | public void onLoginCanceled() { | 138 | public void onLoginCanceled() { |
139 | //用户取消登录 | 139 | //用户取消登录 |
140 | Toast.makeText(MainActivity.this, "operate be canceled", Toast.LENGTH_SHORT).show(); | 140 | Toast.makeText(MainActivity.this, "operate be canceled", Toast.LENGTH_SHORT).show(); |
141 | } | 141 | } |
142 | 142 | ||
143 | @Override | 143 | @Override |
144 | public void onLogout() { | 144 | public void onLogout() { |
145 | //用户登出 | 145 | //用户登出 |
146 | 146 | ||
147 | } | 147 | } |
148 | }); | 148 | }); |
149 | 149 | ||
150 | 如上成功登录后收到的GumpUser对象包含以下信息 | 150 | 如上成功登录后收到的GumpUser对象包含以下信息 |
151 | 151 | ||
152 | gumpUser.getUid();//获取用户的userid,此Id标识唯一用户! | 152 | gumpUser.getUid();//获取用户的userid,此Id标识唯一用户! |
153 | gumpUser.getAccountType();//用户类型,此类型数据可从GumpPreference常量获取 | 153 | gumpUser.getAccountType();//用户类型,此类型数据可从GumpPreference常量获取 |
154 | gumpUser.getSessionKey();//登录的sesionKey | 154 | gumpUser.getSessionKey();//登录的sesionKey |
155 | 155 | ||
156 | 156 | ||
157 | #### 3.支付功能 | 157 | #### 3.支付功能 |
158 | 1)使用gump通行证登录,其中除nick外所有参数为必传参数 | 158 | 1)使用gump通行证登录,其中除nick外所有参数为必传参数 |
159 | 159 | ||
160 | Bundle payInfo = new Bundle(); | 160 | Bundle payInfo = new Bundle(); |
161 | payInfo.putString("nick", "thi"); | 161 | payInfo.putString("nick", "thi"); |
162 | payInfo.putString("product", "元宝"); | 162 | payInfo.putString("product", "元宝"); |
163 | payInfo.putFloat("amount", 40.0f); | 163 | payInfo.putFloat("amount", 40.0f); |
164 | payInfo.putString("extraInfo", "This is demo!"); | 164 | payInfo.putString("extraInfo", "This is demo!"); |
165 | payInfo.putString("serverId", "B4003"); | 165 | payInfo.putString("serverId", "B4003"); |
166 | payInfo.putString("roleId", "10010"); | 166 | payInfo.putString("roleId", "10010"); |
167 | payInfo.putString("sessionKey","sessionkey"); | 167 | payInfo.putString("sessionKey","sessionkey"); |
168 | GumpSDK.pay(MainActivity.this, payInfo,PurchaseCallback); | 168 | GumpSDK.pay(MainActivity.this, payInfo,PurchaseCallback); |
169 | 调用pay方法时,必须穿入一个bundle对象,包含如上字段,除nick和roleId外所有字段必须全部包含,其中sessionKey为登录时返回的sessionKey | 169 | 调用pay方法时,必须穿入一个bundle对象,包含如上字段,除nick和roleId外所有字段必须全部包含,其中sessionKey为登录时返回的sessionKey |
170 | 170 | ||
171 | 171 | ||
172 | 2)IAP支付 | 172 | 2)IAP支付 |
173 | 173 | ||
174 | Bundle payInfo = new Bundle(); | 174 | Bundle payInfo = new Bundle(); |
175 | payInfo.putString("product", "gp_skuId"); | 175 | payInfo.putString("product", "gp_skuId"); |
176 | payInfo.putFloat("amount", 0.1f); | 176 | payInfo.putFloat("amount", 0.1f); |
177 | payInfo.putString("extraInfo", "This is demo!"); | 177 | payInfo.putString("extraInfo", "This is demo!"); |
178 | payInfo.putString("serverId", "100"); | 178 | payInfo.putString("serverId", "100"); |
179 | payInfo.putString("roleId","100123"); | 179 | payInfo.putString("roleId","100123"); |
180 | GumpSDK.iap(MainActivity.this, payInfo, PurchaseCallback); | 180 | GumpSDK.iap(MainActivity.this, payInfo, PurchaseCallback); |
181 | 181 | ||
182 | 3)PurchaseCallback为支付状态回调接口,此接口含有3个方法 | 182 | 3)PurchaseCallback为支付状态回调接口,此接口含有3个方法 |
183 | 183 | ||
184 | @Override | 184 | @Override |
185 | public void onPurchaseCompleted(PurchaseResult result) { | 185 | public void onPurchaseCompleted(PurchaseResult result) { |
186 | Log.i(TAG,"purchase completed"); | 186 | Log.i(TAG,"purchase completed"); |
187 | } | 187 | } |
188 | 188 | ||
189 | @Override | 189 | @Override |
190 | public void onPurchaseError(int code, String msg) { | 190 | public void onPurchaseError(int code, String msg) { |
191 | Log.i(TAG,"purchase error"); | 191 | Log.i(TAG,"purchase error"); |
192 | } | 192 | } |
193 | 193 | ||
194 | @Override | 194 | @Override |
195 | public void onPurchaseCanceled() { | 195 | public void onPurchaseCanceled() { |
196 | Log.i(TAG,"purchase canceled"); | 196 | Log.i(TAG,"purchase canceled"); |
197 | } | 197 | } |
198 | 198 | ||
199 | #### 4.注销登录 | 199 | #### 4.注销登录 |
200 | 200 | ||
201 | GumpSDK.logout(Activity); | 201 | GumpSDK.logout(Activity); |
202 | 当此方法调用后,用户退出登录,并会通过LoginStateListener接口通知调用程序!为了便于用户切换登录账户,请在游戏内提供用户注销的触发按钮 | 202 | 当此方法调用后,用户退出登录,并会通过LoginStateListener接口通知调用程序!为了便于用户切换登录账户,请在游戏内提供用户注销的触发按钮 |
203 | ## 第二章 常见问题 | 203 | ## 第二章 常见问题 |
204 | ### 问题1: 如何避免混淆对SDK的影响? | 204 | ### 问题1: 如何避免混淆对SDK的影响? |
205 | 解答:有些开发者对接入了SDK的程序进行混淆时,有可能会覆盖某些java | 205 | 解答:有些开发者对接入了SDK的程序进行混淆时,有可能会覆盖某些java |
206 | 类,导致SDK无法正常工作,解决方法如下: | 206 | 类,导致SDK无法正常工作,解决方法如下: |
207 | Ø 请开发者在混淆配置文件proguard.cfg或proguard-project.txt的最后加上 | 207 | Ø 请开发者在混淆配置文件proguard.cfg或proguard-project.txt的最后加上 |
208 | 208 | ||
209 | -keepattributes *Annotation*,InnerClasses,SourceFile,LineNumberTable | 209 | -keepattributes *Annotation*,InnerClasses,SourceFile,LineNumberTable |
210 | -keep public class * extends android.app.Service | 210 | -keep public class * extends android.app.Service |
211 | -keep public class com.google.vending.licensing.ILicensingService | 211 | -keep public class com.google.vending.licensing.ILicensingService |
212 | -keep public class com.android.vending.licensing.ILicensingService | 212 | -keep public class com.android.vending.licensing.ILicensingService |
213 | -keep class com.g.root.view.* {*;} | 213 | -keep class com.g.root.view.* {*;} |
214 | -keep class com.g.root.web.* {*;} | 214 | -keep class com.g.root.web.* {*;} |
215 | -keep class com.g.root.bridge.impl.*{*;} | 215 | -keep class com.g.root.bridge.impl.*{*;} |
216 | 216 | ||
217 | 217 | ||
218 | 使得混淆的时候不会影响SDK的命名空间。 | 218 | 使得混淆的时候不会影响SDK的命名空间。 |