Commit 82eb378ad802eed9b4d32f996154603026751d6c
1 parent
d95d6c5fd8
Exists in
master
3.2.0文档更新
Showing 1 changed file with 79 additions and 35 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 |  | 33 |  |
| 34 | 图1 | 34 | 图1 |
| 35 | 35 | ||
| 36 | 2.导入工程后,右键此工程,在Properties->Android中选中此工程为library工程(勾选红色方框标识处)如图2。 | 36 | 2.导入工程后,右键此工程,在Properties->Android中选中此工程为library工程(勾选红色方框标识处)如图2。 |
| 37 |  | 37 |  |
| 38 | 图 2 | 38 | 图 2 |
| 39 | ### 2. 添加资源工程 | 39 | ### 2. 添加资源工程 |
| 40 | 添加资源工程为游戏项目的 library。右键游戏项目,在Properties->Android中点击Add添加资源工程为项目工程的library,结果如图3。 | 40 | 添加资源工程为游戏项目的 library。右键游戏项目,在Properties->Android中点击Add添加资源工程为项目工程的library,结果如图3。 |
| 41 |  | 41 |  |
| 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 |  | 52 |  |
| 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 | <activity | ||
| 96 | android:name="com.facebook.FacebookActivity" | ||
| 97 | android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" | ||
| 98 | android:label="@string/app_name" | ||
| 99 | android:theme="@android:style/Theme.Translucent.NoTitleBar" /> | ||
| 95 | 100 | ||
| 96 | 101 | ||
| 97 | #### 2、 向Gump平台索要游戏ID(GID),完成代码接入 | 102 | #### 2、 向Gump平台索要游戏ID(GID),完成代码接入 |
| 98 | 1.调用GumpSDK前需要执行初始化。 | 103 | 正式开始接入逻辑代码前,先介绍下一些附加配置,以方便代码接入 |
| 99 | 若不需要分渠道 | ||
| 100 | |||
| 101 | GumpSDK.init(Context,Appid, Appkey); | ||
| 102 | 如果需要定义渠道,必须使用如下方法 | ||
| 103 | |||
| 104 | GumpSDK.init(Context,Appid, Appkey,ChannelId); | ||
| 105 | *gump logo的显示控制方法,此方法参数指定是否显示GumpLogo | 104 | *gump logo的显示控制方法,此方法参数指定是否显示GumpLogo |
| 106 | 105 | ||
| 107 | GumpSDK.setShowLogo(boolean); | 106 | GumpSDK.setShowLogo(boolean); |
| 108 | *横竖屏控制,默认为横屏,参数为false即为竖屏 | 107 | *横竖屏控制,默认为横屏,参数为false即为竖屏 |
| 109 | 108 | ||
| 110 | GumpSDK.setScreenLandscape(true); | 109 | GumpSDK.setScreenLandscape(true); |
| 110 | *debug模式设置 | ||
| 111 | |||
| 112 | GumpSDK.setDebugState(true); | ||
| 113 | 1.调用GumpSDK前需要执行初始化。 | ||
| 114 | |||
| 115 | 若不需要分渠道 | ||
| 116 | |||
| 117 | GumpSDK.init(Context,Appid, Appkey,InitializeCallback); | ||
| 118 | 如果需要定义渠道,必须使用如下方法 | ||
| 119 | |||
| 120 | GumpSDK.init(Context,Appid, Appkey,ChannelId,InitializeCallback); | ||
| 121 | |||
| 122 | InitializeCallback为初始化回调接口,此接口只有一个回调方法initComplete(int result) result标识是否初始化成功,当result等于GumpSDK.CODE.OK时为成功,其他为失败 | ||
| 123 | |||
| 111 | 2.调用GumpSDK的开始方法,将执行登录流程,需要一个Activity实例作参数 | 124 | 2.调用GumpSDK的开始方法,将执行登录流程,需要一个Activity实例作参数 |
| 112 | 125 | ||
| 113 | GumpSDK.start(Activity); | 126 | GumpSDK.start(Activity); |
| 114 | 开发者需要在调用的Activity里重写onActivityResult方法以接受用户的登录结果,通常如下: | 127 | 在此之前,开发者需要注册用户状态监听以接受用户的登录/登出通知,通常如下: |
| 115 | 128 | ||
| 116 | //登录请求返回结果 | 129 | GumpSDK.setUserStateListener(new LoginStateListener() { |
| 117 | if (requestCode == GumpSDK.LOGIN_REQUEST_CODE) { | 130 | @Override |
| 118 | if (resultCode == RESULT_OK) { | 131 | public void onLoginSuccess(GumpUser gumpUser) { |
| 119 | String uid = data.getIntExtra("userId", -1); | 132 | //登录成功,用户信息包含在GumpUser对象里 |
| 120 | int accountType = data.getIntExtra("accountType", -1); | 133 | } |
| 121 | String sessionkey = data.getStringExtra("sessionKey"); | 134 | |
| 122 | 135 | @Override | |
| 123 | } else if (resultCode == RESULT_CANCELED) { | 136 | public void onLoginFailed(int code, String msg) { |
| 124 | Toast.makeText(this, "operate be canceled", Toast.LENGTH_SHORT).show(); | 137 | //登录出错,根据错误码和信息判断错误类型 |
| 125 | } | 138 | Toast.makeText(MainActivity.this, "Login failed:code="+code+",message="+msg, Toast.LENGTH_SHORT).show(); |
| 126 | } | 139 | } |
| 140 | |||
| 141 | @Override | ||
| 142 | public void onLoginCanceled() { | ||
| 143 | //用户取消登录 | ||
| 144 | Toast.makeText(MainActivity.this, "operate be canceled", Toast.LENGTH_SHORT).show(); | ||
| 145 | } | ||
| 146 | |||
| 147 | @Override | ||
| 148 | public void onLogout() { | ||
| 149 | //用户登出 | ||
| 150 | |||
| 151 | } | ||
| 152 | }); | ||
| 127 | 153 | ||
| 128 | 如上将收到成功登录用的userid,此Id标识唯一用户! | 154 | 如上成功登录后收到的GumpUser对象包含以下信息 |
| 155 | |||
| 156 | gumpUser.getUid();//获取用户的userid,此Id标识唯一用户! | ||
| 157 | gumpUser.getAccountType();//用户类型,此类型数据可从GumpPreference常量获取 | ||
| 158 | gumpUser.getSessionKey();//登录的sesionKey | ||
| 159 | |||
| 129 | 160 | ||
| 130 | 3.支付功能 | 161 | 3.支付功能 |
| 131 | 1)使用gump通行证登录,其中serverId为必传参数 | 162 | 1)使用gump通行证登录,其中serverId为必传参数 |
| 132 | 163 | ||
| 133 | Bundle payInfo = new Bundle(); | 164 | Bundle payInfo = new Bundle(); |
| 134 | payInfo.putString("nick", "thi"); | 165 | payInfo.putString("nick", "thi"); |
| 135 | payInfo.putString("product", "元宝"); | 166 | payInfo.putString("product", "元宝"); |
| 136 | payInfo.putFloat("amount", 40.0f); | 167 | payInfo.putFloat("amount", 40.0f); |
| 137 | payInfo.putString("extraInfo", "This is demo!"); | 168 | payInfo.putString("extraInfo", "This is demo!"); |
| 138 | payInfo.putString("serverId", "B4003"); | 169 | payInfo.putString("serverId", "B4003"); |
| 139 | payInfo.putString("roleId", "10010"); | 170 | payInfo.putString("roleId", "10010"); |
| 140 | GumpSDK.pay(MainActivity.this, payInfo); | 171 | GumpSDK.pay(MainActivity.this, payInfo,PurchaseCallback); |
| 141 | 调用pay方法时,必须穿入一个bundle对象,包含如上字段,除serverId外可以设置值为空,但是字段必须全部包含 | 172 | 调用pay方法时,必须穿入一个bundle对象,包含如上字段,除serverId外可以设置值为空,但是字段必须全部包含 |
| 142 | 2)未使用gump通行证登录,需要传入用户id,serverId为必传参数 | 173 | 2)未使用gump通行证登录,需要传入用户id,serverId为必传参数 |
| 143 | 174 | ||
| 144 | Bundle payInfo = new Bundle(); | 175 | Bundle payInfo = new Bundle(); |
| 145 | payInfo.putString("nick", "thi"); | 176 | payInfo.putString("nick", "thi"); |
| 146 | payInfo.putString("product", "元宝"); | 177 | payInfo.putString("product", "元宝"); |
| 147 | payInfo.putFloat("amount", 40.0f); | 178 | payInfo.putFloat("amount", 40.0f); |
| 148 | payInfo.putString("extraInfo", "This is demo!"); | 179 | payInfo.putString("extraInfo", "This is demo!"); |
| 149 | payInfo.putString("serverId", "B4003"); | 180 | payInfo.putString("serverId", "B4003"); |
| 150 | payInfo.putString("roleId", "10010"); | 181 | payInfo.putString("roleId", "10010"); |
| 151 | GumpSDK.pay(MainActivity.this, payInfo,"1021"); | 182 | GumpSDK.pay(MainActivity.this, payInfo,"1021",PurchaseCallback); |
| 183 | |||
| 184 | PurchaseCallback为支付状态回调接口,此接口含有3个方法 | ||
| 185 | |||
| 186 | @Override | ||
| 187 | public void onPurchaseCompleted(PurchaseResult result) { | ||
| 188 | Log.i(TAG,"purchase completed"); | ||
| 189 | } | ||
| 190 | |||
| 191 | @Override | ||
| 192 | public void onPurchaseError(int code, String msg) { | ||
| 193 | Log.i(TAG,"purchase error"); | ||
| 194 | } | ||
| 195 | |||
| 196 | @Override | ||
| 197 | public void onPurchaseCanceled() { | ||
| 198 | Log.i(TAG,"purchase canceled"); | ||
| 199 | } | ||
| 200 | |||
| 152 | 5.注销登录 | 201 | 5.注销登录 |
| 153 | 202 | ||
| 154 | GumpSDK.logout(Activity,GumpSDK.Callback); | 203 | GumpSDK.logout(Activity); |
| 155 | 当此方法调用后,用户退出登录,并会通过callback接口通知调用程序! | 204 | 当此方法调用后,用户退出登录,并会通过LoginStateListener接口通知调用程序! |
| 156 | ## 第二章 常见问题 | 205 | ## 第二章 常见问题 |
| 157 | ### 问题1: 如何避免混淆对SDK的影响? | 206 | ### 问题1: 如何避免混淆对SDK的影响? |
| 158 | 解答:有些开发者对接入了SDK的程序进行混淆时,有可能会覆盖某些java | 207 | 解答:有些开发者对接入了SDK的程序进行混淆时,有可能会覆盖某些java |
| 159 | 类,导致SDK无法正常工作,解决方法如下: | 208 | 类,导致SDK无法正常工作,解决方法如下: |
| 160 | Ø 请开发者在混淆配置文件proguard.cfg或proguard-project.txt的最后加上 | 209 | Ø 请开发者在混淆配置文件proguard.cfg或proguard-project.txt的最后加上 |
| 161 | 210 | ||
| 162 | -keepattributes *Annotation* | 211 | -keepattributes *Annotation*,InnerClasses,SourceFile,LineNumberTable |
| 163 | -keep public class * extends android.app.Service | 212 | -keep public class * extends android.app.Service |
| 164 | -keep public class com.google.vending.licensing.ILicensingService | 213 | -keep public class com.google.vending.licensing.ILicensingService |
| 165 | -keep public class com.android.vending.licensing.ILicensingService | 214 | -keep public class com.android.vending.licensing.ILicensingService |
| 166 | -keep class com.gumptech.sdk.view.* {*;} | 215 | -keep class com.gumptech.sdk.view.* {*;} |
| 167 | -keep class com.gumptech.sdk.web.* {*;} | 216 | -keep class com.gumptech.sdk.web.* {*;} |