Commit d3c7882c1912dc65cdcbf5f64a57b094f89e8374
0 parents
Exists in
master
first commit:4.+
Showing 2 changed files with 214 additions and 0 deletions Side-by-side Diff
GameSDK4.0.0-release.aar
No preview for this file type
IntegrationGuide.md
| ... | ... | @@ -0,0 +1,214 @@ |
| 1 | +# Gump SDK 4 for Android接入文档 | |
| 2 | + | |
| 3 | +V4.0.0 | |
| 4 | +2016年09月23日 | |
| 5 | + | |
| 6 | +##版本概述 | |
| 7 | + | |
| 8 | +此版本为使用AndroidStudio开发的第一个版本,一改eclipse的工程依赖方式,使用aar的方式提供sdk接入包,除功能外,相对上一版本没有继承关系,请按此文档描述接入. | |
| 9 | + | |
| 10 | +此SDK适用android2.3以上系统. | |
| 11 | + | |
| 12 | +## 第一章 接入指南 | |
| 13 | +###1.依赖导入 | |
| 14 | +将aar添加到libs目录下,然后配置gradle | |
| 15 | +以下为必须项 | |
| 16 | + | |
| 17 | + repositories{ | |
| 18 | + flatDir{ | |
| 19 | + dirs 'libs' | |
| 20 | + } | |
| 21 | + } | |
| 22 | + dependencies { | |
| 23 | + compile(name:'GameSDK-release',ext:'aar') | |
| 24 | + } | |
| 25 | + | |
| 26 | +可选接入facebook登录并使用sdk方式时,需要增加依赖(web方式登录请忽略) | |
| 27 | + | |
| 28 | + compile 'com.facebook.android:facebook-android-sdk:4.4.0' | |
| 29 | + | |
| 30 | +可选接入vk登录时,需要导入vkLibrary工程,并配置模块依赖,如下 | |
| 31 | + | |
| 32 | + compile project(':vksdk_library') | |
| 33 | + | |
| 34 | +###2.修改AndroidManifest.xml文件 | |
| 35 | +首先添加必要的权限,如下所示: | |
| 36 | + | |
| 37 | + <uses-permission android:name="android.permission.INTERNET" /> | |
| 38 | + <uses-permission android:name="android.permission.READ_PHONE_STATE" /> | |
| 39 | + <uses-permission android:name="android.permission.BLUETOOTH" /> | |
| 40 | + <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> | |
| 41 | + <uses-permission android:name="android.permission.WRITE_SETTINGS"/> | |
| 42 | + <uses-permission android:name="android.permission.GET_ACCOUNTS"/> | |
| 43 | + <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> | |
| 44 | + <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> | |
| 45 | + <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/> | |
| 46 | + <uses-permission android:name="android.permission.SEND_SMS"/> | |
| 47 | + <!-- VERY IMPORTANT! Don't forget this permission, or in-app billing won't work. --> | |
| 48 | + <uses-permission android:name="com.android.vending.BILLING" /> | |
| 49 | + | |
| 50 | +其次注册相应的Activity,具体如下: | |
| 51 | + | |
| 52 | + <activity | |
| 53 | + android:name="com.gumptech.sdk.ContainerActivity" | |
| 54 | + android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout" | |
| 55 | + android:windowSoftInputMode="stateAlwaysHidden|adjustPan" | |
| 56 | + android:launchMode="singleTask" | |
| 57 | + android:theme="@style/Theme.TransparentWin" > | |
| 58 | + </activity> | |
| 59 | + <activity | |
| 60 | + android:name="com.gumptech.sdk.PaymentActivity" | |
| 61 | + android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout" | |
| 62 | + android:launchMode="singleTask" | |
| 63 | + android:theme="@android:style/Theme.Translucent.NoTitleBar" > | |
| 64 | + <intent-filter> | |
| 65 | + <category android:name="android.intent.category.DEFAULT" /> | |
| 66 | + <action android:name="android.intent.action.VIEW" /> | |
| 67 | + <category android:name="android.intent.category.BROWSABLE" /> | |
| 68 | + <data | |
| 69 | + android:host="com.gump.sdk" | |
| 70 | + android:scheme="gump+游戏的appId" /> | |
| 71 | + </intent-filter> | |
| 72 | + </activity> | |
| 73 | + <activity | |
| 74 | + android:name="com.gumptech.sdk.ExchangeWindow" | |
| 75 | + android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout" | |
| 76 | + android:theme="@style/Theme.WinForExchange" > | |
| 77 | + </activity> | |
| 78 | + | |
| 79 | + <service android:name="com.gumptech.sdk.PushService" /> | |
| 80 | + <!-- facebook --> | |
| 81 | + <activity | |
| 82 | + android:name="com.facebook.FacebookActivity" | |
| 83 | + android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" | |
| 84 | + android:label="@string/app_name" | |
| 85 | + android:theme="@android:style/Theme.Translucent.NoTitleBar" /> | |
| 86 | + <!-- vk登录使用,若不接入vk,不需配置 --> | |
| 87 | + <activity android:name="com.vk.sdk.VKOpenAuthActivity" /> | |
| 88 | + <activity | |
| 89 | + android:name="com.vk.sdk.VKServiceActivity" | |
| 90 | + android:label="ServiceActivity" | |
| 91 | + android:theme="@style/VK.Transparent" /> | |
| 92 | + | |
| 93 | +###3.向Gump平台索要游戏ID(AppID),完成代码接入 | |
| 94 | +正式开始接入逻辑代码前,先介绍下一些附加设置,以方便代码接入 | |
| 95 | + | |
| 96 | +*是否打印debug日志 | |
| 97 | + | |
| 98 | + GumpSDK.getSettings().enableDebugLogging(true); | |
| 99 | + | |
| 100 | +*Gump Logo隐藏 | |
| 101 | + | |
| 102 | + GumpSDK.getSettings().setLogoShow(false); | |
| 103 | + | |
| 104 | +*横竖屏控制,默认为横屏,参数为false即为竖屏 | |
| 105 | + | |
| 106 | + GumpSDK.getSettings().setScreenLandscape(true); | |
| 107 | + | |
| 108 | +*设置是否启用Facebook登录和VK登录 | |
| 109 | + | |
| 110 | + GumpSDK.getSettings().setFBEnable(true); | |
| 111 | + GumpSDK.getSettings().setVKEnable(true); | |
| 112 | +*若要强制使用web方式登录facebook | |
| 113 | + | |
| 114 | + GumpSDK.getSettings().forceFBWithWeb(); | |
| 115 | +####1.调用GumpSDK前需要执行初始化。 | |
| 116 | + | |
| 117 | +若不需要分渠道 | |
| 118 | + | |
| 119 | + GumpSDK.init(Context,Appid, Appkey,InitializeCallback); | |
| 120 | +如果需要定义渠道,必须使用如下方法 | |
| 121 | + | |
| 122 | + GumpSDK.init(Context,Appid, Appkey,ChannelId,InitializeCallback); | |
| 123 | + | |
| 124 | +InitializeCallback为初始化回调接口,此接口只有一个回调方法initComplete(int result) result标识是否初始化成功,当result等于GumpSDK.CODE.OK时为成功,其他为失败 | |
| 125 | + | |
| 126 | +####2.调用GumpSDK的开始方法,将执行登录流程,需要一个Activity实例作参数 | |
| 127 | + | |
| 128 | + GumpSDK.start(Activity); | |
| 129 | +在此之前,开发者需要注册用户状态监听以接受用户的登录/登出通知,通常如下: | |
| 130 | + | |
| 131 | + GumpSDK.setUserStateListener(new LoginStateListener() { | |
| 132 | + @Override | |
| 133 | + public void onLoginSuccess(GumpUser gumpUser) { | |
| 134 | + //登录成功,用户信息包含在GumpUser对象里 | |
| 135 | + } | |
| 136 | + | |
| 137 | + @Override | |
| 138 | + public void onLoginFailed(int code, String msg) { | |
| 139 | + //登录出错,根据错误码和信息判断错误类型 | |
| 140 | + Toast.makeText(MainActivity.this, "Login failed:code="+code+",message="+msg, Toast.LENGTH_SHORT).show(); | |
| 141 | + } | |
| 142 | + | |
| 143 | + @Override | |
| 144 | + public void onLoginCanceled() { | |
| 145 | + //用户取消登录 | |
| 146 | + Toast.makeText(MainActivity.this, "operate be canceled", Toast.LENGTH_SHORT).show(); | |
| 147 | + } | |
| 148 | + | |
| 149 | + @Override | |
| 150 | + public void onLogout() { | |
| 151 | + //用户登出 | |
| 152 | + | |
| 153 | + } | |
| 154 | + }); | |
| 155 | + | |
| 156 | +如上成功登录后收到的GumpUser对象包含以下信息 | |
| 157 | + | |
| 158 | + gumpUser.getUid();//获取用户的userid,此Id标识唯一用户! | |
| 159 | + gumpUser.getAccountType();//用户类型,此类型数据可从GumpPreference常量获取 | |
| 160 | + gumpUser.getSessionKey();//登录的sesionKey | |
| 161 | + | |
| 162 | + | |
| 163 | +####3.支付功能 | |
| 164 | +1)使用gump通行证登录,其中除nick和roleId外所有参数为必传参数 | |
| 165 | + | |
| 166 | + Bundle payInfo = new Bundle(); | |
| 167 | + payInfo.putString("nick", "thi"); | |
| 168 | + payInfo.putString("product", "元宝"); | |
| 169 | + payInfo.putFloat("amount", 40.0f); | |
| 170 | + payInfo.putString("extraInfo", "This is demo!"); | |
| 171 | + payInfo.putString("serverId", "B4003"); | |
| 172 | + payInfo.putString("roleId", "10010"); | |
| 173 | + payInfo.putString("sessionKey","sessionkey"); | |
| 174 | + GumpSDK.pay(MainActivity.this, payInfo,PurchaseCallback); | |
| 175 | +调用pay方法时,必须穿入一个bundle对象,包含如上字段,除nick和roleId外所有字段必须全部包含,其中sessionKey为登录时返回的sessionKey | |
| 176 | + | |
| 177 | + | |
| 178 | +2)PurchaseCallback为支付状态回调接口,此接口含有3个方法 | |
| 179 | + | |
| 180 | + @Override | |
| 181 | + public void onPurchaseCompleted(PurchaseResult result) { | |
| 182 | + Log.i(TAG,"purchase completed"); | |
| 183 | + } | |
| 184 | + | |
| 185 | + @Override | |
| 186 | + public void onPurchaseError(int code, String msg) { | |
| 187 | + Log.i(TAG,"purchase error"); | |
| 188 | + } | |
| 189 | + | |
| 190 | + @Override | |
| 191 | + public void onPurchaseCanceled() { | |
| 192 | + Log.i(TAG,"purchase canceled"); | |
| 193 | + } | |
| 194 | + | |
| 195 | +####4.注销登录 | |
| 196 | + | |
| 197 | + GumpSDK.logout(Activity); | |
| 198 | +当此方法调用后,用户退出登录,并会通过LoginStateListener接口通知调用程序! | |
| 199 | +## 第二章 常见问题 | |
| 200 | +### 问题1: 如何避免混淆对SDK的影响? | |
| 201 | +解答:有些开发者对接入了SDK的程序进行混淆时,有可能会覆盖某些java | |
| 202 | +类,导致SDK无法正常工作,解决方法如下: | |
| 203 | +Ø 请开发者在混淆配置文件proguard.cfg或proguard-project.txt的最后加上 | |
| 204 | + | |
| 205 | + -keepattributes *Annotation*,InnerClasses,SourceFile,LineNumberTable | |
| 206 | + -keep public class * extends android.app.Service | |
| 207 | + -keep public class com.google.vending.licensing.ILicensingService | |
| 208 | + -keep public class com.android.vending.licensing.ILicensingService | |
| 209 | + -keep class com.gumptech.sdk.view.* {*;} | |
| 210 | + -keep class com.gumptech.sdk.web.* {*;} | |
| 211 | + -keep class com.gumptech.sdk.bridge.impl.*{*;} | |
| 212 | + | |
| 213 | + | |
| 214 | +使得混淆的时候不会影响SDK的命名空间。 | |
| 0 | 215 | \ No newline at end of file |