Commit 88e1ea28828e693bcea760bb11789aec7e9957c5
Exists in
master
Merge branch 'master' of http://git.letsgame.mobi/document/gumptech-document
Showing 1 changed file Inline Diff
doc/AndroidDocument.md
1 | # Gump Android SDK使用文档 | 1 | # Gump Android SDK使用文档 |
2 | 2 | ||
3 | 3 | ||
4 | 接入手册 | 4 | 接入手册 |
5 | V 1.5 | 5 | V 1.5 |
6 | 2014年07月23日 | 6 | 2014年07月23日 |
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" /> | ||
71 | <!--coda--> | ||
72 | <uses-permission android:name="android.permission.RECEIVE_SMS" /> | ||
73 | <uses-permission android:name="android.permission.READ_SMS" /> | ||
74 | <uses-permission android:name="android.permission.WRITE_SMS" /> | ||
75 | <uses-permission android:name="android.permission.GET_TASKS" /> | ||
70 | <uses-feature android:name="android.hardware.camera" android:required="false" /> | 76 | <uses-feature android:name="android.hardware.camera" android:required="false" /> |
71 | <uses-feature android:name="android.hardware.camera.autofocus" android:required="false" /> | 77 | <uses-feature android:name="android.hardware.camera.autofocus" android:required="false" /> |
72 | <!-- 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. --> |
73 | <uses-permission android:name="com.android.vending.BILLING" /> | 79 | <uses-permission android:name="com.android.vending.BILLING" /> |
74 | 80 | ||
75 | 其次注册相应的Activity,具体如下: | 81 | 其次注册相应的Activity,具体如下: |
76 | 82 | ||
77 | <activity | 83 | <activity |
78 | android:name="com.gumptech.sdk.ContainerActivity" | 84 | android:name="com.gumptech.sdk.ContainerActivity" |
79 | android:theme="@style/container_dialog" | 85 | android:theme="@style/container_dialog" |
80 | android:configChanges="orientation|screenLayout" > | 86 | android:configChanges="orientation|screenLayout" > |
81 | </activity> | 87 | </activity> |
82 | <activity | 88 | <activity |
83 | android:name="com.facebook.LoginActivity" | 89 | android:name="com.facebook.LoginActivity" |
84 | android:theme="@android:style/Theme.Translucent.NoTitleBar" > | 90 | android:theme="@android:style/Theme.Translucent.NoTitleBar" > |
85 | </activity> | 91 | </activity> |
86 | <activity | 92 | <activity |
87 | android:name="com.gumptech.sdk.PaymentActivity" | 93 | android:name="com.gumptech.sdk.PaymentActivity" |
88 | android:configChanges="orientation|screenLayout" | 94 | android:configChanges="orientation|screenLayout" |
89 | android:theme="@android:style/Theme.Translucent.NoTitleBar" > | 95 | android:theme="@android:style/Theme.Translucent.NoTitleBar" > |
90 | </activity> | 96 | </activity> |
91 | <activity | 97 | <activity |
92 | android:name="com.gumptech.sdk.ExchangeWindow" | 98 | android:name="com.gumptech.sdk.ExchangeWindow" |
93 | android:configChanges="orientation|screenLayout" | 99 | android:configChanges="orientation|screenLayout" |
94 | android:theme="@style/ex_win" > | 100 | android:theme="@style/ex_win" > |
95 | </activity> | 101 | </activity> |
96 | <!-- paypal --> | 102 | <!-- paypal --> |
97 | <service | 103 | <service |
98 | android:name="com.paypal.android.sdk.payments.PayPalService" | 104 | android:name="com.paypal.android.sdk.payments.PayPalService" |
99 | android:exported="false" /> | 105 | android:exported="false" /> |
100 | 106 | ||
101 | <activity android:name="com.paypal.android.sdk.payments.PaymentActivity" /> | 107 | <activity android:name="com.paypal.android.sdk.payments.PaymentActivity" /> |
102 | <activity android:name="com.paypal.android.sdk.payments.LoginActivity" /> | 108 | <activity android:name="com.paypal.android.sdk.payments.LoginActivity" /> |
103 | <activity android:name="com.paypal.android.sdk.payments.PaymentMethodActivity" /> | 109 | <activity android:name="com.paypal.android.sdk.payments.PaymentMethodActivity" /> |
104 | <activity android:name="com.paypal.android.sdk.payments.PaymentConfirmActivity" /> | 110 | <activity android:name="com.paypal.android.sdk.payments.PaymentConfirmActivity" /> |
105 | <activity android:name="com.paypal.android.sdk.payments.PayPalFuturePaymentActivity" /> | 111 | <activity android:name="com.paypal.android.sdk.payments.PayPalFuturePaymentActivity" /> |
106 | <activity android:name="com.paypal.android.sdk.payments.FuturePaymentConsentActivity" /> | 112 | <activity android:name="com.paypal.android.sdk.payments.FuturePaymentConsentActivity" /> |
107 | <activity android:name="com.paypal.android.sdk.payments.FuturePaymentInfoActivity" /> | 113 | <activity android:name="com.paypal.android.sdk.payments.FuturePaymentInfoActivity" /> |
108 | <activity | 114 | <activity |
109 | android:name="io.card.payment.CardIOActivity" | 115 | android:name="io.card.payment.CardIOActivity" |
110 | android:configChanges="keyboardHidden|orientation" /> | 116 | android:configChanges="keyboardHidden|orientation" /> |
111 | <activity android:name="io.card.payment.DataEntryActivity" /> | 117 | <activity android:name="io.card.payment.DataEntryActivity" /> |
118 | <activity | ||
119 | android:name="com.android.easy2pay.Easy2PayScreen" | ||
120 | android:theme="@android:style/Theme.Translucent.NoTitleBar" /> | ||
121 | <activity | ||
122 | android:name="com.codapayments.sdk.pay.CodaWeb" | ||
123 | android:alwaysRetainTaskState="true" | ||
124 | android:configChanges="orientation|screenSize" | ||
125 | android:screenOrientation="unspecified" > | ||
126 | </activity> | ||
127 | |||
128 | <receiver | ||
129 | android:name="com.codapayments.sdk.message.PendingTxnReceiver" | ||
130 | android:enabled="true" > | ||
131 | </receiver> | ||
112 | 132 | ||
113 | #### 2、 向Gump平台索要游戏ID(GID),完成代码接入 | 133 | #### 2、 向Gump平台索要游戏ID(GID),完成代码接入 |
114 | 1.调用GumpSDK前需要执行初始化。 | 134 | 1.调用GumpSDK前需要执行初始化。 |
115 | 若不需要分渠道 | 135 | 若不需要分渠道 |
116 | 136 | ||
117 | GumpSDK.init(Appid, Appkey,FacebookId); | 137 | GumpSDK.init(Context,Appid, Appkey,FacebookId); |
118 | 如果需要定义渠道,必须使用如下方法 | 138 | 如果需要定义渠道,必须使用如下方法 |
119 | 139 | ||
120 | GumpSDK.init(Appid, Appkey,FacebookId,ChannelId); | 140 | GumpSDK.init(Context,Appid, Appkey,FacebookId,ChannelId); |
121 | 2.调用GumpSDK的开始方法,将执行登录流程,需要一个Activity实例作参数 | 141 | 2.调用GumpSDK的开始方法,将执行登录流程,需要一个Activity实例作参数 |
122 | 142 | ||
123 | GumpSDK.start(Activity); | 143 | GumpSDK.start(Activity); |
124 | 开发者需要在调用的Activity里重写onActivityResult方法以接受用户的登录结果,通常如下: | 144 | 开发者需要在调用的Activity里重写onActivityResult方法以接受用户的登录结果,通常如下: |
125 | 145 | ||
126 | //登录请求返回结果 | 146 | //登录请求返回结果 |
127 | if (requestCode == GumpSDK.LOGIN_REQUEST_CODE) { | 147 | if (requestCode == GumpSDK.LOGIN_REQUEST_CODE) { |
128 | if (resultCode == RESULT_OK) { | 148 | if (resultCode == RESULT_OK) { |
129 | int uid = data.getIntExtra("userId", -1); | 149 | int uid = data.getIntExtra("userId", -1); |
130 | int accountType = data.getIntExtra("accountType", -1); | 150 | int accountType = data.getIntExtra("accountType", -1); |
131 | String sessionkey = data.getStringExtra("sessionKey"); | 151 | String sessionkey = data.getStringExtra("sessionKey"); |
132 | 152 | ||
133 | } else if (resultCode == RESULT_CANCELED) { | 153 | } else if (resultCode == RESULT_CANCELED) { |
134 | Toast.makeText(this, "operate be canceled", Toast.LENGTH_SHORT).show(); | 154 | Toast.makeText(this, "operate be canceled", Toast.LENGTH_SHORT).show(); |
135 | } | 155 | } |
136 | } | 156 | } |
137 | 157 | ||
138 | 如上将收到成功登录用的userid,此Id标识唯一用户! | 158 | 如上将收到成功登录用的userid,此Id标识唯一用户! |
139 | 3.用户绑定邮箱,并填写密码 | 159 | 3.用户绑定邮箱,并填写密码 |
140 | 160 | ||
141 | GumpSDK.boundMail(MainActivity.this); | 161 | GumpSDK.boundMail(MainActivity.this); |
142 | 开发者需要在调用的Activity里重写onActivityResult方法以接受用户的绑定结果,通常如下: | 162 | 开发者需要在调用的Activity里重写onActivityResult方法以接受用户的绑定结果,通常如下: |
143 | 163 | ||
144 | //绑定邮箱请求返回结果 | 164 | //绑定邮箱请求返回结果 |
145 | if (requestCode == GumpSDK.BOUND_REQUEST_CODE) { | 165 | if (requestCode == GumpSDK.BOUND_REQUEST_CODE) { |
146 | if (resultCode == RESULT_OK) { | 166 | if (resultCode == RESULT_OK) { |
147 | int uid = data.getIntExtra("userId", -1); | 167 | int uid = data.getIntExtra("userId", -1); |
148 | int accountType = data.getIntExtra("accountType", -1); | 168 | int accountType = data.getIntExtra("accountType", -1); |
149 | String sessionkey = data.getStringExtra("sessionKey"); | 169 | String sessionkey = data.getStringExtra("sessionKey"); |
150 | } else if (resultCode == RESULT_CANCELED) { | 170 | } else if (resultCode == RESULT_CANCELED) { |
151 | Toast.makeText(this, "operate be canceled", Toast.LENGTH_SHORT).show(); | 171 | Toast.makeText(this, "operate be canceled", Toast.LENGTH_SHORT).show(); |
152 | } | 172 | } |
153 | } | 173 | } |
154 | 4.支付功能 | 174 | 4.支付功能 |
155 | 1)使用gump通行证登录 | 175 | 1)使用gump通行证登录 |
156 | 176 | ||
157 | Bundle payInfo = new Bundle(); | 177 | Bundle payInfo = new Bundle(); |
158 | payInfo.putString("nick", "thi"); | 178 | payInfo.putString("nick", "thi"); |
159 | payInfo.putString("product", "元宝"); | 179 | payInfo.putString("product", "元宝"); |
160 | payInfo.putFloat("amount", 40.0f); | 180 | payInfo.putFloat("amount", 40.0f); |
161 | payInfo.putString("extraInfo", "This is demo!"); | 181 | payInfo.putString("extraInfo", "This is demo!"); |
162 | payInfo.putString("serverId", "B4003"); | 182 | payInfo.putString("serverId", "B4003"); |
163 | payInfo.putString("roleId", "10010"); | 183 | payInfo.putString("roleId", "10010"); |
164 | GumpSDK.pay(MainActivity.this, payInfo); | 184 | GumpSDK.pay(MainActivity.this, payInfo); |
165 | 调用pay方法时,必须穿入一个bundle对象,包含如上字段,可以设置值为空,但是字段必须全部包含,支付完成仍然通过onActivityResult回调,requestCode为GumpSDK.PAY_REQUEST_CODE,回调信息除code和msg外,还含有orderId和传入的extraInfo. | 185 | 调用pay方法时,必须穿入一个bundle对象,包含如上字段,可以设置值为空,但是字段必须全部包含,支付完成仍然通过onActivityResult回调,requestCode为GumpSDK.PAY_REQUEST_CODE,回调信息除code和msg外,还含有orderId和传入的extraInfo. |
166 | 2)未使用gump通行证登录,需要传入用户id | 186 | 2)未使用gump通行证登录,需要传入用户id |
167 | 187 | ||
168 | Bundle payInfo = new Bundle(); | 188 | Bundle payInfo = new Bundle(); |
169 | payInfo.putString("nick", "thi"); | 189 | payInfo.putString("nick", "thi"); |
170 | payInfo.putString("product", "元宝"); | 190 | payInfo.putString("product", "元宝"); |
171 | payInfo.putFloat("amount", 40.0f); | 191 | payInfo.putFloat("amount", 40.0f); |
172 | payInfo.putString("extraInfo", "This is demo!"); | 192 | payInfo.putString("extraInfo", "This is demo!"); |
173 | payInfo.putString("serverId", "B4003"); | 193 | payInfo.putString("serverId", "B4003"); |
174 | payInfo.putString("roleId", "10010"); | 194 | payInfo.putString("roleId", "10010"); |
175 | GumpSDK.pay(MainActivity.this, payInfo,"1021"); | 195 | GumpSDK.pay(MainActivity.this, payInfo,"1021"); |
176 | 5.注销登录 | 196 | 5.注销登录 |
177 | 197 | ||
178 | GumpSDK.logout(Activity,GumpSDK.Callback); | 198 | GumpSDK.logout(Activity,GumpSDK.Callback); |
179 | 当此方法调用后,用户退出登录,并会通过callback接口通知调用程序! | 199 | 当此方法调用后,用户退出登录,并会通过callback接口通知调用程序! |
180 | ## 第二章 常见问题 | 200 | ## 第二章 常见问题 |
181 | ### 问题1: 如何避免混淆对SDK的影响? | 201 | ### 问题1: 如何避免混淆对SDK的影响? |
182 | 解答:有些开发者对接入了SDK的程序进行混淆时,有可能会覆盖某些java | 202 | 解答:有些开发者对接入了SDK的程序进行混淆时,有可能会覆盖某些java |
183 | 类,导致SDK无法正常工作,解决方法如下: | 203 | 类,导致SDK无法正常工作,解决方法如下: |
184 | Ø 请开发者在混淆配置文件proguard.cfg或proguard-project.txt的最后加上 | 204 | Ø 请开发者在混淆配置文件proguard.cfg或proguard-project.txt的最后加上 |
185 | 205 | ||
186 | -keep class com.gumptech.sdk.GumpSDK{ | 206 | -keep class com.gumptech.sdk.GumpSDK{ |
187 | public static final <fields>; | 207 | public static final <fields>; |
188 | public static void init(java.lang.String,java.lang.String); | 208 | public static void init(java.lang.String,java.lang.String); |
189 | public static void init(java.lang.String,java.lang.String,java.lang.String,java.lang.String); | 209 | public static void init(java.lang.String,java.lang.String,java.lang.String,java.lang.String); |
190 | public static void start(android.app.Activity); | 210 | public static void start(android.app.Activity); |
191 | public static void logout(android.app.Activity); | 211 | public static void logout(android.app.Activity); |
192 | public static void boundMail(android.app.Activity); | 212 | public static void boundMail(android.app.Activity); |
193 | } | 213 | } |
194 | -keep class com.gumptech.sdk.view.* {*;} | 214 | -keep class com.gumptech.sdk.view.* {*;} |
195 | -keep class com.gumptech.sdk.GumpSDK$Callback{ | 215 | -keep class com.gumptech.sdk.GumpSDK$Callback{ |
196 | void onLogout(); | 216 | void onLogout(); |
197 | } | 217 | } |
198 | -keep class com.gumptech.sdk.GumpPreference{ | 218 | -keep class com.gumptech.sdk.GumpPreference{ |
199 | public static final <fields>; | 219 | public static final <fields>; |
200 | } | 220 | } |
201 | -keep class com.facebook.** { *; } | 221 | -keep class com.facebook.** { *; } |
202 | 222 | ||
203 | -keepattributes Signature | 223 | -keepattributes Signature |
204 | 使得混淆的时候不会影响SDK的命名空间。 | 224 | 使得混淆的时候不会影响SDK的命名空间。 |