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