Commit dafcd90c07a6744f86a384997edb8ca2b5ee7d59
1 parent
82eb378ad8
Exists in
master
修改权限设置,修改常见问题
Showing 1 changed file with 3 additions and 5 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 3.2.0 | 
| 6 | 2015年01月08日 | 6 | 2015年07月29日 | 
| 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 | <uses-permission android:name="android.permission.SEND_SMS"/> | ||
| 68 | 69 | ||
| 69 | <!-- 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. --> | 
| 70 | <uses-permission android:name="com.android.vending.BILLING" /> | 71 | <uses-permission android:name="com.android.vending.BILLING" /> | 
| 71 | 72 | ||
| 72 | 其次注册相应的Activity,具体如下: | 73 | 其次注册相应的Activity,具体如下: | 
| 73 | 74 | ||
| 74 | <activity | 75 | <activity | 
| 75 | android:name="com.gumptech.sdk.ContainerActivity" | 76 | android:name="com.gumptech.sdk.ContainerActivity" | 
| 76 | android:theme="@style/container_dialog" | 77 | android:theme="@style/container_dialog" | 
| 77 | android:configChanges="orientation|screenLayout" > | 78 | android:configChanges="orientation|screenLayout" > | 
| 78 | </activity> | 79 | </activity> | 
| 79 | <activity | 80 | <activity | 
| 80 | android:name="com.facebook.LoginActivity" | 81 | android:name="com.facebook.LoginActivity" | 
| 81 | android:theme="@android:style/Theme.Translucent.NoTitleBar" > | 82 | android:theme="@android:style/Theme.Translucent.NoTitleBar" > | 
| 82 | </activity> | 83 | </activity> | 
| 83 | <activity | 84 | <activity | 
| 84 | android:name="com.gumptech.sdk.PaymentActivity" | 85 | android:name="com.gumptech.sdk.PaymentActivity" | 
| 85 | android:configChanges="orientation|screenLayout" | 86 | android:configChanges="orientation|screenLayout" | 
| 86 | android:theme="@android:style/Theme.Translucent.NoTitleBar" > | 87 | android:theme="@android:style/Theme.Translucent.NoTitleBar" > | 
| 87 | </activity> | 88 | </activity> | 
| 88 | <activity | 89 | <activity | 
| 89 | android:name="com.gumptech.sdk.ExchangeWindow" | 90 | android:name="com.gumptech.sdk.ExchangeWindow" | 
| 90 | android:configChanges="orientation|screenLayout" | 91 | android:configChanges="orientation|screenLayout" | 
| 91 | android:theme="@style/ex_win" > | 92 | android:theme="@style/ex_win" > | 
| 92 | </activity> | 93 | </activity> | 
| 93 | <service android:name="com.gumptech.sdk.PushService" > | 94 | <service android:name="com.gumptech.sdk.PushService" > | 
| 94 | </service> | 95 | </service> | 
| 95 | <activity | 96 | <activity | 
| 96 | android:name="com.facebook.FacebookActivity" | 97 | android:name="com.facebook.FacebookActivity" | 
| 97 | android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" | 98 | android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" | 
| 98 | android:label="@string/app_name" | 99 | android:label="@string/app_name" | 
| 99 | android:theme="@android:style/Theme.Translucent.NoTitleBar" /> | 100 | android:theme="@android:style/Theme.Translucent.NoTitleBar" /> | 
| 100 | 101 | ||
| 101 | 102 | ||
| 102 | #### 2、 向Gump平台索要游戏ID(GID),完成代码接入 | 103 | #### 2、 向Gump平台索要游戏ID(GID),完成代码接入 | 
| 103 | 正式开始接入逻辑代码前,先介绍下一些附加配置,以方便代码接入 | 104 | 正式开始接入逻辑代码前,先介绍下一些附加配置,以方便代码接入 | 
| 104 | *gump logo的显示控制方法,此方法参数指定是否显示GumpLogo | 105 | *gump logo的显示控制方法,此方法参数指定是否显示GumpLogo | 
| 105 | 106 | ||
| 106 | GumpSDK.setShowLogo(boolean); | 107 | GumpSDK.setShowLogo(boolean); | 
| 107 | *横竖屏控制,默认为横屏,参数为false即为竖屏 | 108 | *横竖屏控制,默认为横屏,参数为false即为竖屏 | 
| 108 | 109 | ||
| 109 | GumpSDK.setScreenLandscape(true); | 110 | GumpSDK.setScreenLandscape(true); | 
| 110 | *debug模式设置 | 111 | *debug模式设置 | 
| 111 | 112 | ||
| 112 | GumpSDK.setDebugState(true); | 113 | GumpSDK.setDebugState(true); | 
| 113 | 1.调用GumpSDK前需要执行初始化。 | 114 | 1.调用GumpSDK前需要执行初始化。 | 
| 114 | 115 | ||
| 115 | 若不需要分渠道 | 116 | 若不需要分渠道 | 
| 116 | 117 | ||
| 117 | GumpSDK.init(Context,Appid, Appkey,InitializeCallback); | 118 | GumpSDK.init(Context,Appid, Appkey,InitializeCallback); | 
| 118 | 如果需要定义渠道,必须使用如下方法 | 119 | 如果需要定义渠道,必须使用如下方法 | 
| 119 | 120 | ||
| 120 | GumpSDK.init(Context,Appid, Appkey,ChannelId,InitializeCallback); | 121 | GumpSDK.init(Context,Appid, Appkey,ChannelId,InitializeCallback); | 
| 121 | 122 | ||
| 122 | InitializeCallback为初始化回调接口,此接口只有一个回调方法initComplete(int result) result标识是否初始化成功,当result等于GumpSDK.CODE.OK时为成功,其他为失败 | 123 | InitializeCallback为初始化回调接口,此接口只有一个回调方法initComplete(int result) result标识是否初始化成功,当result等于GumpSDK.CODE.OK时为成功,其他为失败 | 
| 123 | 124 | ||
| 124 | 2.调用GumpSDK的开始方法,将执行登录流程,需要一个Activity实例作参数 | 125 | 2.调用GumpSDK的开始方法,将执行登录流程,需要一个Activity实例作参数 | 
| 125 | 126 | ||
| 126 | GumpSDK.start(Activity); | 127 | GumpSDK.start(Activity); | 
| 127 | 在此之前,开发者需要注册用户状态监听以接受用户的登录/登出通知,通常如下: | 128 | 在此之前,开发者需要注册用户状态监听以接受用户的登录/登出通知,通常如下: | 
| 128 | 129 | ||
| 129 | GumpSDK.setUserStateListener(new LoginStateListener() { | 130 | GumpSDK.setUserStateListener(new LoginStateListener() { | 
| 130 | @Override | 131 | @Override | 
| 131 | public void onLoginSuccess(GumpUser gumpUser) { | 132 | public void onLoginSuccess(GumpUser gumpUser) { | 
| 132 | //登录成功,用户信息包含在GumpUser对象里 | 133 | //登录成功,用户信息包含在GumpUser对象里 | 
| 133 | } | 134 | } | 
| 134 | 135 | ||
| 135 | @Override | 136 | @Override | 
| 136 | public void onLoginFailed(int code, String msg) { | 137 | public void onLoginFailed(int code, String msg) { | 
| 137 | //登录出错,根据错误码和信息判断错误类型 | 138 | //登录出错,根据错误码和信息判断错误类型 | 
| 138 | Toast.makeText(MainActivity.this, "Login failed:code="+code+",message="+msg, Toast.LENGTH_SHORT).show(); | 139 | Toast.makeText(MainActivity.this, "Login failed:code="+code+",message="+msg, Toast.LENGTH_SHORT).show(); | 
| 139 | } | 140 | } | 
| 140 | 141 | ||
| 141 | @Override | 142 | @Override | 
| 142 | public void onLoginCanceled() { | 143 | public void onLoginCanceled() { | 
| 143 | //用户取消登录 | 144 | //用户取消登录 | 
| 144 | Toast.makeText(MainActivity.this, "operate be canceled", Toast.LENGTH_SHORT).show(); | 145 | Toast.makeText(MainActivity.this, "operate be canceled", Toast.LENGTH_SHORT).show(); | 
| 145 | } | 146 | } | 
| 146 | 147 | ||
| 147 | @Override | 148 | @Override | 
| 148 | public void onLogout() { | 149 | public void onLogout() { | 
| 149 | //用户登出 | 150 | //用户登出 | 
| 150 | 151 | ||
| 151 | } | 152 | } | 
| 152 | }); | 153 | }); | 
| 153 | 154 | ||
| 154 | 如上成功登录后收到的GumpUser对象包含以下信息 | 155 | 如上成功登录后收到的GumpUser对象包含以下信息 | 
| 155 | 156 | ||
| 156 | gumpUser.getUid();//获取用户的userid,此Id标识唯一用户! | 157 | gumpUser.getUid();//获取用户的userid,此Id标识唯一用户! | 
| 157 | gumpUser.getAccountType();//用户类型,此类型数据可从GumpPreference常量获取 | 158 | gumpUser.getAccountType();//用户类型,此类型数据可从GumpPreference常量获取 | 
| 158 | gumpUser.getSessionKey();//登录的sesionKey | 159 | gumpUser.getSessionKey();//登录的sesionKey | 
| 159 | 160 | ||
| 160 | 161 | ||
| 161 | 3.支付功能 | 162 | 3.支付功能 | 
| 162 | 1)使用gump通行证登录,其中serverId为必传参数 | 163 | 1)使用gump通行证登录,其中serverId为必传参数 | 
| 163 | 164 | ||
| 164 | Bundle payInfo = new Bundle(); | 165 | Bundle payInfo = new Bundle(); | 
| 165 | payInfo.putString("nick", "thi"); | 166 | payInfo.putString("nick", "thi"); | 
| 166 | payInfo.putString("product", "元宝"); | 167 | payInfo.putString("product", "元宝"); | 
| 167 | payInfo.putFloat("amount", 40.0f); | 168 | payInfo.putFloat("amount", 40.0f); | 
| 168 | payInfo.putString("extraInfo", "This is demo!"); | 169 | payInfo.putString("extraInfo", "This is demo!"); | 
| 169 | payInfo.putString("serverId", "B4003"); | 170 | payInfo.putString("serverId", "B4003"); | 
| 170 | payInfo.putString("roleId", "10010"); | 171 | payInfo.putString("roleId", "10010"); | 
| 171 | GumpSDK.pay(MainActivity.this, payInfo,PurchaseCallback); | 172 | GumpSDK.pay(MainActivity.this, payInfo,PurchaseCallback); | 
| 172 | 调用pay方法时,必须穿入一个bundle对象,包含如上字段,除serverId外可以设置值为空,但是字段必须全部包含 | 173 | 调用pay方法时,必须穿入一个bundle对象,包含如上字段,除serverId外可以设置值为空,但是字段必须全部包含 | 
| 173 | 2)未使用gump通行证登录,需要传入用户id,serverId为必传参数 | 174 | 2)未使用gump通行证登录,需要传入用户id,serverId为必传参数 | 
| 174 | 175 | ||
| 175 | Bundle payInfo = new Bundle(); | 176 | Bundle payInfo = new Bundle(); | 
| 176 | payInfo.putString("nick", "thi"); | 177 | payInfo.putString("nick", "thi"); | 
| 177 | payInfo.putString("product", "元宝"); | 178 | payInfo.putString("product", "元宝"); | 
| 178 | payInfo.putFloat("amount", 40.0f); | 179 | payInfo.putFloat("amount", 40.0f); | 
| 179 | payInfo.putString("extraInfo", "This is demo!"); | 180 | payInfo.putString("extraInfo", "This is demo!"); | 
| 180 | payInfo.putString("serverId", "B4003"); | 181 | payInfo.putString("serverId", "B4003"); | 
| 181 | payInfo.putString("roleId", "10010"); | 182 | payInfo.putString("roleId", "10010"); | 
| 182 | GumpSDK.pay(MainActivity.this, payInfo,"1021",PurchaseCallback); | 183 | GumpSDK.pay(MainActivity.this, payInfo,"1021",PurchaseCallback); | 
| 183 | 184 | ||
| 184 | PurchaseCallback为支付状态回调接口,此接口含有3个方法 | 185 | PurchaseCallback为支付状态回调接口,此接口含有3个方法 | 
| 185 | 186 | ||
| 186 | @Override | 187 | @Override | 
| 187 | public void onPurchaseCompleted(PurchaseResult result) { | 188 | public void onPurchaseCompleted(PurchaseResult result) { | 
| 188 | Log.i(TAG,"purchase completed"); | 189 | Log.i(TAG,"purchase completed"); | 
| 189 | } | 190 | } | 
| 190 | 191 | ||
| 191 | @Override | 192 | @Override | 
| 192 | public void onPurchaseError(int code, String msg) { | 193 | public void onPurchaseError(int code, String msg) { | 
| 193 | Log.i(TAG,"purchase error"); | 194 | Log.i(TAG,"purchase error"); | 
| 194 | } | 195 | } | 
| 195 | 196 | ||
| 196 | @Override | 197 | @Override | 
| 197 | public void onPurchaseCanceled() { | 198 | public void onPurchaseCanceled() { | 
| 198 | Log.i(TAG,"purchase canceled"); | 199 | Log.i(TAG,"purchase canceled"); | 
| 199 | } | 200 | } | 
| 200 | 201 | ||
| 201 | 5.注销登录 | 202 | 5.注销登录 | 
| 202 | 203 | ||
| 203 | GumpSDK.logout(Activity); | 204 | GumpSDK.logout(Activity); | 
| 204 | 当此方法调用后,用户退出登录,并会通过LoginStateListener接口通知调用程序! | 205 | 当此方法调用后,用户退出登录,并会通过LoginStateListener接口通知调用程序! | 
| 205 | ## 第二章 常见问题 | 206 | ## 第二章 常见问题 | 
| 206 | ### 问题1: 如何避免混淆对SDK的影响? | 207 | ### 问题1: 如何避免混淆对SDK的影响? | 
| 207 | 解答:有些开发者对接入了SDK的程序进行混淆时,有可能会覆盖某些java | 208 | 解答:有些开发者对接入了SDK的程序进行混淆时,有可能会覆盖某些java | 
| 208 | 类,导致SDK无法正常工作,解决方法如下: | 209 | 类,导致SDK无法正常工作,解决方法如下: | 
| 209 | Ø 请开发者在混淆配置文件proguard.cfg或proguard-project.txt的最后加上 | 210 | Ø 请开发者在混淆配置文件proguard.cfg或proguard-project.txt的最后加上 | 
| 210 | 211 | ||
| 211 | -keepattributes *Annotation*,InnerClasses,SourceFile,LineNumberTable | 212 | -keepattributes *Annotation*,InnerClasses,SourceFile,LineNumberTable | 
| 212 | -keep public class * extends android.app.Service | 213 | -keep public class * extends android.app.Service | 
| 213 | -keep public class com.google.vending.licensing.ILicensingService | 214 | -keep public class com.google.vending.licensing.ILicensingService | 
| 214 | -keep public class com.android.vending.licensing.ILicensingService | 215 | -keep public class com.android.vending.licensing.ILicensingService | 
| 215 | -keep class com.gumptech.sdk.view.* {*;} | 216 | -keep class com.gumptech.sdk.view.* {*;} | 
| 216 | -keep class com.gumptech.sdk.web.* {*;} | 217 | -keep class com.gumptech.sdk.web.* {*;} | 
| 217 | 218 | ||
| 218 | 219 | ||
| 219 | 使得混淆的时候不会影响SDK的命名空间。 | 220 | 使得混淆的时候不会影响SDK的命名空间。 | 
| 220 | ### 问题2:后台已经配置ok的情况下,支付列表仍然为空或登录总是出错? | ||
| 221 | 解答:sdk在debug模式下使用的默认服务器地址是开发环境地址,此地址区别于正式环境地址,为开发调试用;若进行线上调试或正式环境测试,需要使用release模式来进行! |