Commit e5622414e8657fb87b68f1e31013525dcb4c2c46

Authored by 赵康
1 parent 1e9b540dd7
Exists in master

声明支付时的必传参数

Showing 1 changed file with 3 additions and 3 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 2015年01月08日 6 2015年01月08日
7 7
8 快速入口: 8 快速入口:
9 [支付部分服务端回调文档](http://git.letsgame.mobi/document/gumptech-document/blob/master/doc/ServerDocument.md) 9 [支付部分服务端回调文档](http://git.letsgame.mobi/document/gumptech-document/blob/master/doc/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 - [问题2:后台已经配置ok的情况下,支付列表仍然为空或登录总是出错?](http://git.letsgame.mobi/document/gumptech-document/blob/master/doc/AndroidDocument.md#2-ok) 21 - [问题2:后台已经配置ok的情况下,支付列表仍然为空或登录总是出错?](http://git.letsgame.mobi/document/gumptech-document/blob/master/doc/AndroidDocument.md#2-ok)
22 22
23 23
24 24
25 25
26 ## 第一章 接入指南 26 ## 第一章 接入指南
27 配置环境 27 配置环境
28 28
29 本接口API 适用于Android2.2以上各版本Android平台。 29 本接口API 适用于Android2.2以上各版本Android平台。
30 ### 1. 导入资源工程 30 ### 1. 导入资源工程
31 1.将LoginSDK资源工程拷贝到工作空间,在eclipse中的导航栏右键弹出如图1画面,选择Import导入资源工程,如图1. 31 1.将LoginSDK资源工程拷贝到工作空间,在eclipse中的导航栏右键弹出如图1画面,选择Import导入资源工程,如图1.
32 32
33 ![](images/1.png) 33 ![](images/1.png)
34 图1 34 图1
35 35
36 2.导入工程后,右键此工程,在Properties->Android中选中此工程为library工程(勾选红色方框标识处)如图2。 36 2.导入工程后,右键此工程,在Properties->Android中选中此工程为library工程(勾选红色方框标识处)如图2。
37 ![](images/2.png) 37 ![](images/2.png)
38 图 2 38 图 2
39 ### 2. 添加资源工程 39 ### 2. 添加资源工程
40 添加资源工程为游戏项目的 library。右键游戏项目,在Properties->Android中点击Add添加资源工程为项目工程的library,结果如图3。 40 添加资源工程为游戏项目的 library。右键游戏项目,在Properties->Android中点击Add添加资源工程为项目工程的library,结果如图3。
41 ![](images/3.png) 41 ![](images/3.png)
42 图 3 42 图 3
43 43
44 44
45 注意:如果ADT版本低于14,ADT不支持jar包自动引入,请手动拷贝libs到您的工作 45 注意:如果ADT版本低于14,ADT不支持jar包自动引入,请手动拷贝libs到您的工作
46 空间。 46 空间。
47 47
48 Eclipse查看ADT版本号的方法: 48 Eclipse查看ADT版本号的方法:
49 Help==>About Eclips点击Android对应的图标就可以查看版本了. 49 Help==>About Eclips点击Android对应的图标就可以查看版本了.
50 如图,红色框部分就是ADT版本号。 50 如图,红色框部分就是ADT版本号。
51 51
52 ![](images/4.png) 52 ![](images/4.png)
53 53
54 54
55 ### 3. 代码实现 55 ### 3. 代码实现
56 #### 1、 修改AndroidManifest.xml文件 56 #### 1、 修改AndroidManifest.xml文件
57 首先添加必要的权限,如下所示: 57 首先添加必要的权限,如下所示:
58 58
59 <uses-permission android:name="android.permission.INTERNET" /> 59 <uses-permission android:name="android.permission.INTERNET" />
60 <uses-permission android:name="android.permission.READ_PHONE_STATE" /> 60 <uses-permission android:name="android.permission.READ_PHONE_STATE" />
61 <uses-permission android:name="android.permission.BLUETOOTH" /> 61 <uses-permission android:name="android.permission.BLUETOOTH" />
62 <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> 62 <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
63 <uses-permission android:name="android.permission.WRITE_SETTINGS"/> 63 <uses-permission android:name="android.permission.WRITE_SETTINGS"/>
64 <uses-permission android:name="android.permission.GET_ACCOUNTS"/> 64 <uses-permission android:name="android.permission.GET_ACCOUNTS"/>
65 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 65 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
66 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 66 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
67 <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/> 67 <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
68 68
69 <!-- VERY IMPORTANT! Don't forget this permission, or in-app billing won't work. --> 69 <!-- VERY IMPORTANT! Don't forget this permission, or in-app billing won't work. -->
70 <uses-permission android:name="com.android.vending.BILLING" /> 70 <uses-permission android:name="com.android.vending.BILLING" />
71 71
72 其次注册相应的Activity,具体如下: 72 其次注册相应的Activity,具体如下:
73 73
74 <activity 74 <activity
75 android:name="com.gumptech.sdk.ContainerActivity" 75 android:name="com.gumptech.sdk.ContainerActivity"
76 android:theme="@style/container_dialog" 76 android:theme="@style/container_dialog"
77 android:configChanges="orientation|screenLayout" > 77 android:configChanges="orientation|screenLayout" >
78 </activity> 78 </activity>
79 <activity 79 <activity
80 android:name="com.facebook.LoginActivity" 80 android:name="com.facebook.LoginActivity"
81 android:theme="@android:style/Theme.Translucent.NoTitleBar" > 81 android:theme="@android:style/Theme.Translucent.NoTitleBar" >
82 </activity> 82 </activity>
83 <activity 83 <activity
84 android:name="com.gumptech.sdk.PaymentActivity" 84 android:name="com.gumptech.sdk.PaymentActivity"
85 android:configChanges="orientation|screenLayout" 85 android:configChanges="orientation|screenLayout"
86 android:theme="@android:style/Theme.Translucent.NoTitleBar" > 86 android:theme="@android:style/Theme.Translucent.NoTitleBar" >
87 </activity> 87 </activity>
88 <activity 88 <activity
89 android:name="com.gumptech.sdk.ExchangeWindow" 89 android:name="com.gumptech.sdk.ExchangeWindow"
90 android:configChanges="orientation|screenLayout" 90 android:configChanges="orientation|screenLayout"
91 android:theme="@style/ex_win" > 91 android:theme="@style/ex_win" >
92 </activity> 92 </activity>
93 <service android:name="com.gumptech.sdk.PushService" > 93 <service android:name="com.gumptech.sdk.PushService" >
94 </service> 94 </service>
95 95
96 96
97 #### 2、 向Gump平台索要游戏ID(GID),完成代码接入 97 #### 2、 向Gump平台索要游戏ID(GID),完成代码接入
98 1.调用GumpSDK前需要执行初始化。 98 1.调用GumpSDK前需要执行初始化。
99 若不需要分渠道 99 若不需要分渠道
100 100
101 GumpSDK.init(Context,Appid, Appkey); 101 GumpSDK.init(Context,Appid, Appkey);
102 如果需要定义渠道,必须使用如下方法 102 如果需要定义渠道,必须使用如下方法
103 103
104 GumpSDK.init(Context,Appid, Appkey,ChannelId); 104 GumpSDK.init(Context,Appid, Appkey,ChannelId);
105 *gump logo的显示控制方法,此方法参数指定是否显示GumpLogo 105 *gump logo的显示控制方法,此方法参数指定是否显示GumpLogo
106 106
107 GumpSDK.setShowLogo(boolean); 107 GumpSDK.setShowLogo(boolean);
108 *横竖屏控制,默认为横屏,参数为false即为竖屏 108 *横竖屏控制,默认为横屏,参数为false即为竖屏
109 109
110 GumpSDK.setScreenLandscape(true); 110 GumpSDK.setScreenLandscape(true);
111 2.调用GumpSDK的开始方法,将执行登录流程,需要一个Activity实例作参数 111 2.调用GumpSDK的开始方法,将执行登录流程,需要一个Activity实例作参数
112 112
113 GumpSDK.start(Activity); 113 GumpSDK.start(Activity);
114 开发者需要在调用的Activity里重写onActivityResult方法以接受用户的登录结果,通常如下: 114 开发者需要在调用的Activity里重写onActivityResult方法以接受用户的登录结果,通常如下:
115 115
116 //登录请求返回结果 116 //登录请求返回结果
117 if (requestCode == GumpSDK.LOGIN_REQUEST_CODE) { 117 if (requestCode == GumpSDK.LOGIN_REQUEST_CODE) {
118 if (resultCode == RESULT_OK) { 118 if (resultCode == RESULT_OK) {
119 String uid = data.getIntExtra("userId", -1); 119 String uid = data.getIntExtra("userId", -1);
120 int accountType = data.getIntExtra("accountType", -1); 120 int accountType = data.getIntExtra("accountType", -1);
121 String sessionkey = data.getStringExtra("sessionKey"); 121 String sessionkey = data.getStringExtra("sessionKey");
122 122
123 } else if (resultCode == RESULT_CANCELED) { 123 } else if (resultCode == RESULT_CANCELED) {
124 Toast.makeText(this, "operate be canceled", Toast.LENGTH_SHORT).show(); 124 Toast.makeText(this, "operate be canceled", Toast.LENGTH_SHORT).show();
125 } 125 }
126 } 126 }
127 127
128 如上将收到成功登录用的userid,此Id标识唯一用户! 128 如上将收到成功登录用的userid,此Id标识唯一用户!
129 129
130 3.支付功能 130 3.支付功能
131 1)使用gump通行证登录 131 1)使用gump通行证登录,其中serverId为必传参数
132 132
133 Bundle payInfo = new Bundle(); 133 Bundle payInfo = new Bundle();
134 payInfo.putString("nick", "thi"); 134 payInfo.putString("nick", "thi");
135 payInfo.putString("product", "元宝"); 135 payInfo.putString("product", "元宝");
136 payInfo.putFloat("amount", 40.0f); 136 payInfo.putFloat("amount", 40.0f);
137 payInfo.putString("extraInfo", "This is demo!"); 137 payInfo.putString("extraInfo", "This is demo!");
138 payInfo.putString("serverId", "B4003"); 138 payInfo.putString("serverId", "B4003");
139 payInfo.putString("roleId", "10010"); 139 payInfo.putString("roleId", "10010");
140 GumpSDK.pay(MainActivity.this, payInfo); 140 GumpSDK.pay(MainActivity.this, payInfo);
141 调用pay方法时,必须穿入一个bundle对象,包含如上字段,可以设置值为空,但是字段必须全部包含,支付完成仍然通过onActivityResult回调,requestCode为GumpSDK.PAY_REQUEST_CODE,回调信息除code和msg外,还含有orderId和传入的extraInfo. 141 调用pay方法时,必须穿入一个bundle对象,包含如上字段,除serverId外可以设置值为空,但是字段必须全部包含
142 2)未使用gump通行证登录,需要传入用户id 142 2)未使用gump通行证登录,需要传入用户id,serverId为必传参数
143 143
144 Bundle payInfo = new Bundle(); 144 Bundle payInfo = new Bundle();
145 payInfo.putString("nick", "thi"); 145 payInfo.putString("nick", "thi");
146 payInfo.putString("product", "元宝"); 146 payInfo.putString("product", "元宝");
147 payInfo.putFloat("amount", 40.0f); 147 payInfo.putFloat("amount", 40.0f);
148 payInfo.putString("extraInfo", "This is demo!"); 148 payInfo.putString("extraInfo", "This is demo!");
149 payInfo.putString("serverId", "B4003"); 149 payInfo.putString("serverId", "B4003");
150 payInfo.putString("roleId", "10010"); 150 payInfo.putString("roleId", "10010");
151 GumpSDK.pay(MainActivity.this, payInfo,"1021"); 151 GumpSDK.pay(MainActivity.this, payInfo,"1021");
152 5.注销登录 152 5.注销登录
153 153
154 GumpSDK.logout(Activity,GumpSDK.Callback); 154 GumpSDK.logout(Activity,GumpSDK.Callback);
155 当此方法调用后,用户退出登录,并会通过callback接口通知调用程序! 155 当此方法调用后,用户退出登录,并会通过callback接口通知调用程序!
156 ## 第二章 常见问题 156 ## 第二章 常见问题
157 ### 问题1: 如何避免混淆对SDK的影响? 157 ### 问题1: 如何避免混淆对SDK的影响?
158 解答:有些开发者对接入了SDK的程序进行混淆时,有可能会覆盖某些java 158 解答:有些开发者对接入了SDK的程序进行混淆时,有可能会覆盖某些java
159 类,导致SDK无法正常工作,解决方法如下: 159 类,导致SDK无法正常工作,解决方法如下:
160 Ø 请开发者在混淆配置文件proguard.cfg或proguard-project.txt的最后加上 160 Ø 请开发者在混淆配置文件proguard.cfg或proguard-project.txt的最后加上
161 161
162 -keepattributes *Annotation* 162 -keepattributes *Annotation*
163 -keep public class * extends android.app.Service 163 -keep public class * extends android.app.Service
164 -keep public class com.google.vending.licensing.ILicensingService 164 -keep public class com.google.vending.licensing.ILicensingService
165 -keep public class com.android.vending.licensing.ILicensingService 165 -keep public class com.android.vending.licensing.ILicensingService
166 -keep class com.gumptech.sdk.view.* {*;} 166 -keep class com.gumptech.sdk.view.* {*;}
167 -keep class com.gumptech.sdk.web.* {*;} 167 -keep class com.gumptech.sdk.web.* {*;}
168 -keep class com.gumptech.sdk.GumpSDK$Callback{ 168 -keep class com.gumptech.sdk.GumpSDK$Callback{
169 void onLogout(); 169 void onLogout();
170 } 170 }
171 -keep class com.gumptech.sdk.GumpPreference{ 171 -keep class com.gumptech.sdk.GumpPreference{
172 public static final <fields>; 172 public static final <fields>;
173 } 173 }
174 174
175 使得混淆的时候不会影响SDK的命名空间。 175 使得混淆的时候不会影响SDK的命名空间。
176 ### 问题2:后台已经配置ok的情况下,支付列表仍然为空或登录总是出错? 176 ### 问题2:后台已经配置ok的情况下,支付列表仍然为空或登录总是出错?
177 解答:sdk在debug模式下使用的默认服务器地址是开发环境地址,此地址区别于正式环境地址,为开发调试用;若进行线上调试或正式环境测试,需要使用release模式来进行! 177 解答:sdk在debug模式下使用的默认服务器地址是开发环境地址,此地址区别于正式环境地址,为开发调试用;若进行线上调试或正式环境测试,需要使用release模式来进行!
178 一般在IDE中直接run应用到设备上使用的是debug证书安装,此时即处于debug模式;若要使用正式环境,应该使用正式证书签名打包后进行安装! 178 一般在IDE中直接run应用到设备上使用的是debug证书安装,此时即处于debug模式;若要使用正式环境,应该使用正式证书签名打包后进行安装!