Commit b58707f79b6e2d9237acd31086c9479843e0e3f6
1 parent
cfd1541f6b
Exists in
master
init
Showing 1 changed file with 275 additions and 0 deletions Inline Diff
AndroidDocument.md
1 | |||
2 | |||
3 | |||
4 | |||
5 | |||
6 | |||
7 | # Gump Android SDK使用文档 | ||
8 | |||
9 | |||
10 | |||
11 | |||
12 | |||
13 | |||
14 | |||
15 | |||
16 | |||
17 | |||
18 | |||
19 | 接入手册 | ||
20 | V 1.5 | ||
21 | 2014年07月23日 | ||
22 | |||
23 | |||
24 | |||
25 | |||
26 | |||
27 | |||
28 | |||
29 | |||
30 | ## 目录 | ||
31 | |||
32 | 第一章 接入指南 3 | ||
33 | 配置环境 3 | ||
34 | 1. 导入资源工程 3 | ||
35 | 2. 添加资源工程 4 | ||
36 | 3. 代码实现 5 | ||
37 | 第二章 常见问题 6 | ||
38 | 问题1: 如何避免混淆对SDK的影响? 6 | ||
39 | |||
40 | |||
41 | |||
42 | |||
43 | |||
44 | |||
45 | |||
46 | |||
47 | |||
48 | |||
49 | |||
50 | |||
51 | |||
52 | |||
53 | |||
54 | |||
55 | |||
56 | |||
57 | |||
58 | |||
59 | |||
60 | |||
61 | |||
62 | |||
63 | ## 第一章 接入指南 | ||
64 | 配置环境 | ||
65 | |||
66 | 本接口API 适用于Android2.2以上各版本Android平台。 | ||
67 | 1. 导入资源工程 | ||
68 | 1.将LoginSDK资源工程拷贝到工作空间,在eclipse中的导航栏右键弹出如图1画面,选择Import导入资源工程,如图1. | ||
69 | |||
70 | |||
71 | |||
72 | |||
73 | |||
74 | |||
75 | |||
76 | |||
77 | |||
78 | |||
79 | |||
80 | |||
81 | |||
82 | |||
83 | |||
84 | |||
85 | |||
86 | |||
87 | |||
88 | |||
89 | |||
90 | |||
91 | |||
92 | |||
93 | |||
94 | |||
95 | |||
96 | |||
97 | 图1 | ||
98 | |||
99 | |||
100 | |||
101 | |||
102 | |||
103 | |||
104 | 2.导入工程后,右键此工程,在Properties->Android中选中此工程为library工程(勾选红色方框标识处)如图2。 | ||
105 | |||
106 | |||
107 | |||
108 | |||
109 | |||
110 | |||
111 | |||
112 | |||
113 | |||
114 | |||
115 | |||
116 | |||
117 | |||
118 | |||
119 | |||
120 | |||
121 | 图 2 | ||
122 | 2. 添加资源工程 | ||
123 | 添加资源工程为游戏项目的 library。右键游戏项目,在Properties->Android中点击Add添加资源工程为项目工程的library,结果如图3。 | ||
124 | |||
125 | |||
126 | |||
127 | |||
128 | |||
129 | |||
130 | |||
131 | |||
132 | |||
133 | |||
134 | |||
135 | |||
136 | 图 3 | ||
137 | |||
138 | 注意:如果ADT版本低于14,ADT不支持jar包自动引入,请手动拷贝libs到您的工作 | ||
139 | 空间。 | ||
140 | |||
141 | Eclipse查看ADT版本号的方法: | ||
142 | Help==>About Eclips点击Android对应的图标就可以查看版本了. | ||
143 | 如图,红色框部分就是ADT版本号。 | ||
144 | |||
145 | |||
146 | |||
147 | |||
148 | |||
149 | |||
150 | |||
151 | |||
152 | |||
153 | |||
154 | |||
155 | |||
156 | 3. 代码实现 | ||
157 | 1、 修改AndroidManifest.xml文件 | ||
158 | 首先添加必要的权限,如下所示: | ||
159 | <uses-permission android:name="android.permission.INTERNET" /> | ||
160 | <uses-permission android:name="android.permission.READ_PHONE_STATE" /> | ||
161 | <uses-permission android:name="android.permission.BLUETOOTH" /> | ||
162 | <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> | ||
163 | <uses-permission android:name="android.permission.WRITE_SETTINGS"/> | ||
164 | <uses-permission android:name="android.permission.GET_ACCOUNTS"/> | ||
165 | <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> | ||
166 | <!-- for card.io card scanning --> | ||
167 | <uses-permission android:name="android.permission.CAMERA" /> | ||
168 | <uses-permission android:name="android.permission.VIBRATE" /> | ||
169 | <uses-feature android:name="android.hardware.camera" android:required="false" /> | ||
170 | <uses-feature android:name="android.hardware.camera.autofocus" android:required="false" /> | ||
171 | <!-- VERY IMPORTANT! Don't forget this permission, or in-app billing won't work. --> | ||
172 | <uses-permission android:name="com.android.vending.BILLING" /> | ||
173 | 其次注册相应的Activity,具体如下: | ||
174 | <activity | ||
175 | android:name="com.gumptech.sdk.ContainerActivity" | ||
176 | android:theme="@style/container_dialog" | ||
177 | android:configChanges="orientation|screenLayout" > | ||
178 | </activity> | ||
179 | <activity | ||
180 | android:name="com.facebook.LoginActivity" | ||
181 | android:theme="@android:style/Theme.Translucent.NoTitleBar" > | ||
182 | </activity> | ||
183 | <activity | ||
184 | android:name="com.gumptech.sdk.PaymentActivity" | ||
185 | android:configChanges="orientation|screenLayout" | ||
186 | android:theme="@android:style/Theme.Translucent.NoTitleBar" > | ||
187 | </activity> | ||
188 | <!-- paypal --> | ||
189 | <service | ||
190 | android:name="com.paypal.android.sdk.payments.PayPalService" | ||
191 | android:exported="false" /> | ||
192 | |||
193 | <activity android:name="com.paypal.android.sdk.payments.PaymentActivity" /> | ||
194 | <activity android:name="com.paypal.android.sdk.payments.LoginActivity" /> | ||
195 | <activity android:name="com.paypal.android.sdk.payments.PaymentMethodActivity" /> | ||
196 | <activity android:name="com.paypal.android.sdk.payments.PaymentConfirmActivity" /> | ||
197 | <activity android:name="com.paypal.android.sdk.payments.PayPalFuturePaymentActivity" /> | ||
198 | <activity android:name="com.paypal.android.sdk.payments.FuturePaymentConsentActivity" /> | ||
199 | <activity android:name="com.paypal.android.sdk.payments.FuturePaymentInfoActivity" /> | ||
200 | <activity | ||
201 | android:name="io.card.payment.CardIOActivity" | ||
202 | android:configChanges="keyboardHidden|orientation" /> | ||
203 | <activity android:name="io.card.payment.DataEntryActivity" /> | ||
204 | 2、 向Gump平台索要游戏ID(GID),完成代码接入 | ||
205 | 1.调用GumpSDK前需要执行初始化。 | ||
206 | 若需要不需要分渠道 | ||
207 | GumpSDK.init(Appid, Appkey,FacebookId); | ||
208 | 如果需要定义渠道,必须使用如下方法 | ||
209 | GumpSDK.init(Appid, Appkey,FacebookId,ChannelId); | ||
210 | 2.调用GumpSDK的开始方法,将执行登录流程,需要一个Activity实例作参数 | ||
211 | GumpSDK.start(Activity); | ||
212 | 开发者需要在调用的Activity里重写onActivityResult方法以接受用户的登录结果,通常如下: | ||
213 | //登录请求返回结果 | ||
214 | if (requestCode == GumpSDK.LOGIN_REQUEST_CODE) { | ||
215 | if (resultCode == RESULT_OK) { | ||
216 | int uid = data.getIntExtra("userId", -1); | ||
217 | int accountType = data.getIntExtra("accountType", -1); | ||
218 | String sessionkey = data.getStringExtra("sessionKey"); | ||
219 | |||
220 | } else if (resultCode == RESULT_CANCELED) { | ||
221 | Toast.makeText(this, "operate be canceled", Toast.LENGTH_SHORT).show(); | ||
222 | } | ||
223 | } | ||
224 | 如上将收到成功登录用的userid,此Id标识唯一用户! | ||
225 | 3.用户绑定邮箱,并填写密码 | ||
226 | GumpSDK.boundMail(MainActivity.this); | ||
227 | 开发者需要在调用的Activity里重写onActivityResult方法以接受用户的绑定结果,通常如下: | ||
228 | //绑定邮箱请求返回结果 | ||
229 | if (requestCode == GumpSDK.BOUND_REQUEST_CODE) { | ||
230 | if (resultCode == RESULT_OK) { | ||
231 | int uid = data.getIntExtra("userId", -1); | ||
232 | int accountType = data.getIntExtra("accountType", -1); | ||
233 | String sessionkey = data.getStringExtra("sessionKey"); | ||
234 | } else if (resultCode == RESULT_CANCELED) { | ||
235 | Toast.makeText(this, "operate be canceled", Toast.LENGTH_SHORT).show(); | ||
236 | } | ||
237 | } | ||
238 | 4.支付功能 | ||
239 | Bundle payInfo = new Bundle(); | ||
240 | payInfo.putString("nick", "thi"); | ||
241 | payInfo.putString("product", "元宝"); | ||
242 | payInfo.putFloat("amount", 40.0f); | ||
243 | payInfo.putString("extraInfo", "This is demo!"); | ||
244 | GumpSDK.pay(MainActivity.this, payInfo); | ||
245 | 调用pay方法时,必须穿入一个bundle对象,包含如上字段,可以设置值为空,但是字段必须全部包含,支付完成仍然通过onActivityResult回调,requestCode为GumpSDK.PAY_REQUEST_CODE,回调信息除code和msg外,还含有orderId和传入的extraInfo. | ||
246 | 5.注销登录 | ||
247 | GumpSDK.logout(Activity,GumpSDK.Callback); | ||
248 | 当此方法调用后,用户退出登录,并会通过callback接口通知调用程序! | ||
249 | 第二章 常见问题 | ||
250 | --- | ||
251 | 问题1: 如何避免混淆对SDK的影响? | ||
252 | 解答:有些开发者对接入了SDK的程序进行混淆时,有可能会覆盖某些java | ||
253 | 类,导致SDK无法正常工作,解决方法如下: | ||
254 | Ø 请开发者在混淆配置文件proguard.cfg或proguard-project.txt的最后加 | ||
255 | 上 | ||
256 | -keep class com.gumptech.sdk.GumpSDK{ | ||
257 | public static final <fields>; | ||
258 | public static void init(java.lang.String,java.lang.String); | ||
259 | public static void init(java.lang.String,java.lang.String,java.lang.String,java.lang.String); | ||
260 | public static void start(android.app.Activity); | ||
261 | public static void logout(android.app.Activity); | ||
262 | public static void boundMail(android.app.Activity); | ||
263 | } | ||
264 | -keep class com.gumptech.sdk.view.* {*;} | ||
265 | -keep class com.gumptech.sdk.GumpSDK$Callback{ | ||
266 | void onLogout(); | ||
267 | } | ||
268 | -keep class com.gumptech.sdk.GumpPreference{ | ||
269 | public static final <fields>; | ||
270 | } | ||
271 | -keep class com.facebook.** { *; } | ||
272 | |||
273 | -keepattributes Signature | ||
274 | 使得混淆的时候不会影响SDK的命名空间。 | ||
275 | |||
276 |