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