Blame view
README.md
5.74 KB
842cbfbfb
![]() |
1 |
# Gump SDK 5 for Android接入文档 |
020faf4c8
![]() |
2 |
V5 |
998c3827a
![]() |
3 |
2019年08月01日 |
842cbfbfb
![]() |
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
## 版本概述 此版本为使用AndroidStudio开发的版本,使用aar在线依赖的方式提供sdk接入包,相对上一版本没有任何继承关系,请按此文档描述接入. 此SDK适用android4.0以上系统. 本SDK分为两个部分:登录和支付,请按需引用依赖包. ## 第一章 接入指南 ### 1.依赖导入 配置gradle,以下为必须项 repositories{ maven{ url "http://117.50.8.198:8081/nexus/content/repositories/sdk" } } dependencies { |
842cbfbfb
![]() |
23 |
//登录功能依赖 |
9e8388286
![]() |
24 |
implementation 'com.gump:Passport:5.2.2' |
842cbfbfb
![]() |
25 |
//支付功能依赖 |
998c3827a
![]() |
26 |
implementation 'com.gump:Payment:5.2.5' |
842cbfbfb
![]() |
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
} ### 2.修改AndroidManifest.xml文件 首先添加必要的权限,如下所示: <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <!-- VERY IMPORTANT! Don't forget this permission, or in-app billing won't work. --> <uses-permission android:name="com.android.vending.BILLING" /> 创建一个strings 配置如下 <string name="app_id">your_play_games_app_id</string> 增加play games的meta-data配置 <meta-data android:name="com.google.android.gms.games.APP_ID" android:value="@string/app_id"/> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/> ### 3.1 初始化与配置 |
842cbfbfb
![]() |
52 53 54 55 56 57 58 59 60 61 |
*若要使用V4版支付请设置 SDKAgent.getSettings().setPaymentVersion(PaymentVersion.V4); *执行初始化 SDKAgent.init(Context,Appid,ChannelId); ### 3.2 登录接入 |
f905cc410
![]() |
62 63 64 65 66 67 68 69 |
AndroidManifest.xml配置: <activity android:name="com.gump.gpassport.GumpLoginActivity" android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout" android:launchMode="singleTask" android:screenOrientation="behind" android:theme="@style/Theme.AppCompat.Light.NoActionBar"/> |
842cbfbfb
![]() |
70 71 72 73 74 75 76 77 78 79 |
构建Passport实例 passport = new Passport.Builder().context(Context).setListener(StateListener).build(); 其中StateListener为登录状态监听接口,需要实现如下方法 //成功回调,成功事件类型由action枚举对象标识,player是成功返回的玩家对象 void onActionSucced(Actions action, GamePlayer player) //失败回调 void onActionFailured() |
9e8388286
![]() |
80 81 82 83 84 |
Actinos枚举: SIGN 登录 SWITCH_PENDING 切换PlayGame账号,需重启游戏 SWITCH 已切换甘普账号,需重新加载用户角色信息 |
28c9154f7
![]() |
85 86 87 |
调用登录 passport.signIn(Activity); |
9e8388286
![]() |
88 |
|
842cbfbfb
![]() |
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
接下来,添加生命周期处理方法 @Override protected void onResume() { super.onResume(); passport.onResume(); } 处理结果返回 @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (!passport.onActivityResult(requestCode, resultCode, data)) super.onActivityResult(requestCode, resultCode, data); } |
9e8388286
![]() |
104 |
### 3.3 账号联动 |
f905cc410
![]() |
105 106 107 108 |
passport.link(Activity); ### 3.4 账号切换 |
9e8388286
![]() |
109 110 111 |
切换到PlayGame账号 passport.switchAccount(); |
f905cc410
![]() |
112 |
|
f905cc410
![]() |
113 |
|
f905cc410
![]() |
114 |
### 3.5 支付接入 |
842cbfbfb
![]() |
115 116 117 |
注册相应的Activity,具体如下: <activity |
020faf4c8
![]() |
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
android:name="com.gump.payment.PaymentActivity" android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout" android:screenOrientation="behind" android:launchMode="singleTask" android:theme="@style/Theme.Translucent"> <intent-filter> <action android:name="android.intent.action.VIEW"/> <category android:name="android.intent.category.DEFAULT"/> <category android:name="android.intent.category.BROWSABLE"/> <data android:host="com.gump.sdk" android:scheme="gump+游戏的appId"/> </intent-filter> </activity> |
842cbfbfb
![]() |
136 |
|
9e8388286
![]() |
137 138 139 140 141 142 143 144 145 146 |
1)判断是否使用三方支付 Payment.shouldUseCoPay(this, serverId, roleId, new ResultCallback() { @Override public void onResult(boolean isRisk) { //isRisk==true时使用IAB支付,isRisk==false时使用三方支付 } }); 2)三方支付调用 |
842cbfbfb
![]() |
147 148 149 150 151 152 153 154 |
Bundle payInfo = new Bundle(); payInfo.putString("product", "wa2"); payInfo.putFloat("amount", 0.1f); payInfo.putString("extraInfo", "This is demo!"); payInfo.putString("serverId", "100"); payInfo.putString("roleId", "41080"); Payment.pay(Activity, payInfo, PurchaseCallback); |
9e8388286
![]() |
155 |
3)Google IAB支付调用 |
842cbfbfb
![]() |
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
Bundle payInfo = new Bundle(); payInfo.putString("product", "180010"); payInfo.putFloat("amount", 0.1f); payInfo.putString("extraInfo", "This is demo!"); payInfo.putString("serverId", "100"); payInfo.putString("roleId", "41080"); Payment.launchIAP(Activity, payInfo, PurchaseCallback); PurchaseCallback为支付状态回调接口,此接口含有3个方法 @Override public void onPurchaseCompleted(PurchaseResult result) { Log.i(TAG,"purchase completed"); } @Override public void onPurchaseError(int code, String msg) { Log.i(TAG,"purchase error"); } @Override public void onPurchaseCanceled() { Log.i(TAG,"purchase canceled"); } ## 第二章 常见问题 ### 问题1: 如何避免混淆对SDK的影响? 解答:有些开发者对接入了SDK的程序进行混淆时,有可能会覆盖某些java 类,导致SDK无法正常工作,解决方法如下: Ø 请开发者在混淆配置文件proguard.cfg或proguard-project.txt的最后加上 -keep class com.gump.payment.web.* {*;} 使得混淆的时候不会影响SDK的命名空间。 |