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