U8SDK——渠道SDK接入详解(以百度SDK为例)
之前在说渠道SDK接入的时候,我们留了个尾巴没说。很多童鞋在开始使用u8sdk的时候,经常会问道。虽然之前写了一篇 UC SDK接入的Demo文章,但是很多童鞋看了还是不清楚,怎么基于u8sdk来完成新渠道SDK的接入。
下面我们继续以百度渠道为例完整详细地演示一遍,怎么基于u8sdk框架来接入一个新的渠道SDK
首先,拿到百度的SDK,我们一样会去看SDK提供的接入说明文档,知道百度SDK主要需要接入登陆和支付两大功能
首先将U8SDK的抽象层工程导入到eclipse中。然后新建一个Android工程叫U8SDK_Baidu,并将U8SDK引用到该工程(怎么在eclipse中添加依赖工程请看 这里)。添加完毕之后,紧接着把百度SDK需要的jar包拷贝到U8SDK_Baidu工程的libs目录下。然后就可以在U8SDK_Baidu工程中进行百度SDK的接入工作了。新建一个包名,比如叫com.u8.sdk。包名建好之后,先啥都不用想,新建三个类:BaiduUser,BaiduPay,BaiduSDK.其中:
BaiduUser需要实现com.u8.sdk.IUser接口。并且拥有一个参数的构造函数,参数类型是Activity
BaiduPay需要实现com.u8.sdk.IPay接口。并且拥有一个参数的构造函数,参数类型是Activity
BaiduSDK是一个单例类。关于如何在java中实现单例模式,请看 这里
所有其他SDK都是类似的。比如X渠道,那么必定会有对应这三个类:XUser implements IUser; XPay implements IPay; XSDK.getInstance();
之前介绍 U8SDK抽象层时说过,U8SDK采用插件式的设计模式,所以,我们将用户相关的功能定义为一个User插件;当支付相关的功能定义为一个Pay插件。具体的类代表分别是IUser接口和IPay接口。
所以,在接入具体的SDK时,我们需要实现这两个插件。对应的,我们就必须定义一个XUser和XPay来分别实现IUser和IPay接口。如果后面你需要加入其它的功能,比如分享,统计等功能,你可以在u8sdk抽象层中定义一个IShare,IStat接口,来代表分享插件和统计插件即可。
那么BaiduSDK这个单例主要来做什么呢?BaiduSDK这个单例类,我们是用来做具体的接入工作的。你在接SDK的时候,看他提供的Demo和文档里面说,必须接入登陆方法,支付方法啥的。这些接入工作全都放在BaiduSDK这个单例类里面完成。
比如BaiduSDK类里面你已经实现了两个方法:login和pay。分别对应是百度SDK的登陆和支付。那么,在BaiduUser类的实现方法login中,直接通过BaiduSDK.getInstance().login()方法调用即可实现登陆功能。在BaiduPay类的实现方法中,直接通过BaiduSDK.getInstance().pay()方法调用即可调用支付功能。
这样整个接入工作就简单了。所有的接口都封装在XSDK这个单例类里面。XUser和XPay里面不做具体的接入逻辑,仅仅是调用XSDK这个单例类中对应的方法而已。
SDK一般都需要初始化,如果渠道没有具体的要求,我们一般将SDK的初始化放在XUser的构造函数中调用,而XUser是在activity的onCreate方法中实例化的,所以,也就是游戏一启动,就开始了SDK的初始化操作。
如果某些渠道要求在Application的onCreate或者attachBaseContext方法中初始化或者进行一些其他的操作,那么你需要参照 u8sdk中关于Application的设计来完成对应的调用。说到Application,百度SDK也要求程序必须继承他们提供的BDGameApplication。根据之前我们说的u8sdk中Application的设计,我们可以很轻松的做到。这里不再赘述。
对于还需要的其他辅助类可以自行添加在工程中。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 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 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 |
package com.u8.sdk; import android.content.Context; import android.content.res.Configuration; import com.baidu.gamesdk.BDGameApplication; /*** * Baidu SDK 需要自定义的Application,我们继承BDGameApplication,同时需要配置到SDK_Manifest.xml中 * */ public class BaiduApplication extends BDGameApplication implements IApplicationListener{ @Override public void onProxyCreate() { super.onCreate(); } @Override public void onProxyAttachBaseContext (Context base) { super.attachBaseContext(base); } @Override public void onProxyConfigurationChanged(Configuration config) { super.onConfigurationChanged(config); } } package com.u8.sdk; import android.app.Activity; public class BaiduUser implements IUser{ private Activity context ; public BaiduUser(Activity context){ this.context = context; BaiduSDK. getInstance().initSDK(this. context, U8SDK.getInstance().getSDKParams()); } @Override public void login() { BaiduSDK. getInstance().login(this. context); } } package com.u8.sdk; import android.app.Activity; public class BaiduPay implements IPay{ private Activity context ; public BaiduPay(Activity context){ this.context = context; } @Override public void pay(PayParams data ) { BaiduSDK. getInstance().pay(this. context, data); } } package com.u8.sdk; import com.baidu.gamesdk.ActivityAdPage; import com.baidu.gamesdk.ActivityAnalytics; import com.baidu.gamesdk.BDGameSDK; import com.baidu.gamesdk.BDGameSDKSetting; import com.baidu.gamesdk.IResponse; import com.baidu.gamesdk.ResultCode; import com.baidu.gamesdk.ActivityAdPage.Listener; import com.baidu.gamesdk.BDGameSDKSetting.Domain; import com.baidu.platformsdk.PayOrderInfo; import com.u8.sdk.baidu.*; import com.u8.sdk.utils.SDKTools; import android.app.Activity; import android.text.TextUtils; import android.util.Log; public class BaiduSDK { enum SDKState{ StateDefault, StateIniting, StateInited, StateLogin, StateLogined } private static BaiduSDK instance; private SDKState state = SDKState.StateDefault; private boolean loginAfterInit = false; private int appID; private String appKey; private Domain domain; private ActivityAdPage mActivityAdPage; private ActivityAnalytics mActivityAnalytics; private BaiduSDK(){ } public static BaiduSDK getInstance(){ if(instance == null){ instance = new BaiduSDK(); } return instance; } private void parseSDKParams(SDKConfigData params){ this.appID = params.getInt("AppID"); this.appKey = params.getString("AppKey"); String domain = params.getString("Domain"); if("DEBUG".equalsIgnoreCase(domain)){ this.domain = Domain.DEBUG; }else{ this.domain = Domain.RELEASE; } } public void initSDK(Activity context, SDKConfigData params){ this.parseSDKParams(params); this.initSDK(context); } public void initSDK(final Activity context){ this.state = SDKState.StateIniting; mActivityAnalytics = new ActivityAnalytics(context); mActivityAdPage = new ActivityAdPage(context, new Listener(){ @Override public void onClose() { // TODO 关闭暂停页, CP可以让玩家继续游戏 } }); U8SDK.getInstance().setActivityCallback(new ActivityCallbackAdapter(){ public void onResume(){ mActivityAdPage.onResume(); mActivityAnalytics.onResume(); } @Override public void onStop() { mActivityAdPage.onStop(); } @Override public void onPause() { mActivityAdPage.onPause(); mActivityAnalytics.onPause(); } @Override public void onDestroy() { mActivityAdPage.onDestroy(); BDGameSDK.destroy(); } }); BDGameSDKSetting mBDGameSDKSetting = new BDGameSDKSetting(); mBDGameSDKSetting.setAppID(this.appID);//APPID设置 mBDGameSDKSetting.setAppKey(this.appKey);//APPKEY设置 mBDGameSDKSetting.setDomain(this.domain);//设置为正式模式 mBDGameSDKSetting.setOrientation(Utils.getOrientation(context)); BDGameSDK.init(context, mBDGameSDKSetting, new IResponse<Void>(){ @Override public void onResponse(int resultCode, String resultDesc, Void extraData) { switch(resultCode){ case ResultCode.INIT_SUCCESS: //初始化成功 state = SDKState.StateInited; U8SDK.getInstance().onResult(U8Code.CODE_INIT_SUCCESS, "baidu sdk init success"); if(loginAfterInit){ login(context); } break; case ResultCode.INIT_FAIL: default: state = SDKState.StateDefault; U8SDK.getInstance().onResult(U8Code.CODE_INIT_FAIL, "baidu sdk init failed."); //初始化失败 } } }); } private LoginResult encodeLoginResult(String token){ String channel = "" + U8SDK.getInstance().getCurrChannel(); String expansion = ""; return new LoginResult(token, channel, expansion); } public void login(final Activity context){ if(state.ordinal() < SDKState.StateInited.ordinal()){ loginAfterInit = true; initSDK(context); return; } if(!SDKTools.isNetworkAvailable(context)){ U8SDK.getInstance().onResult(U8Code.CODE_NO_NETWORK, "The network now is unavailable"); return; } try{ state = SDKState.StateLogin; BDGameSDK.login(new IResponse<Void>() { @Override public void onResponse(int resultCode, String resultDesc, Void extraData) { Log.d("baidu sdk login", "this resultCode is " + resultCode); switch(resultCode){ case ResultCode.LOGIN_SUCCESS: state = SDKState.StateLogined; String token = BDGameSDK.getLoginAccessToken(); U8SDK.getInstance().onResult(U8Code.CODE_LOGIN_SUCCESS, "sid="+";token="+token); LoginResult result = encodeLoginResult(token); U8SDK.getInstance().onLoginResult(result); setSuspendWindowChangeAccountListener(context); setSessionInvalidListener(context); break; case ResultCode.LOGIN_CANCEL: state = SDKState.StateInited; U8SDK.getInstance().onResult(U8Code.CODE_LOGIN_FAIL, "baidu sdk login canceled.resultCode:"+resultCode); break; case ResultCode.LOGIN_FAIL: default: state = SDKState.StateInited; U8SDK.getInstance().onResult(U8Code.CODE_LOGIN_FAIL, "baidu sdk login failed.resultCode:"+resultCode); } } }); }catch(Exception e){ e.printStackTrace(); } } public void logout(){ BDGameSDK.logout(); } public void pay(Activity context, PayParams params){ PayOrderInfo payOrderInfo = buildOrderInfo(params); if(payOrderInfo == null){ return; } if(!isInited()){ U8SDK.getInstance().onResult(U8Code.CODE_INIT_FAIL, "The sdk is not inited."); return; } if(!SDKTools.isNetworkAvailable(context)){ U8SDK.getInstance().onResult(U8Code.CODE_NO_NETWORK, "The network now is unavailable"); return; } BDGameSDK.pay(payOrderInfo, null, new IResponse<PayOrderInfo>(){ @Override public void onResponse(int resultCode, String resultDesc, PayOrderInfo extraData) { switch(resultCode){ case ResultCode.PAY_SUCCESS://支付成功 U8SDK.getInstance().onResult(U8Code.CODE_PAY_SUCCESS, "baidu sdk pay success."); break; case ResultCode.PAY_CANCEL://订单支付取消 U8SDK.getInstance().onResult(U8Code.CODE_PAY_FAIL, "baidu sdk pay canceled."); break; case ResultCode.PAY_FAIL://订单支付失败 U8SDK.getInstance().onResult(U8Code.CODE_PAY_SUCCESS, "baidu sdk pay failed."); break; case ResultCode.PAY_SUBMIT_ORDER://订单已经提交,支付结果未知(比如:已经请求了,但是查询超时) U8SDK.getInstance().onResult(U8Code.CODE_PAY_SUCCESS, "baidu sdk pay order submit success."); break; } } }); } /** * 构建订单信息 */ private PayOrderInfo buildOrderInfo(PayParams params){ String cpOrderId = params.getExtension(); String goodsName = params.getProductName(); String totalAmount = (params.getPrice() * 100) + "";//支付总金额 (以分为单位) int ratio = 1; String extInfo = "";//扩展字段,该信息在支付成功后原样返回给CP if(TextUtils.isEmpty(totalAmount)){ totalAmount = "0"; } PayOrderInfo payOrderInfo = new PayOrderInfo(); payOrderInfo.setCooperatorOrderSerial(cpOrderId); payOrderInfo.setProductName(goodsName); long p = Long.parseLong(totalAmount); payOrderInfo.setTotalPriceCent(p);//以分为单位 payOrderInfo.setRatio(ratio); payOrderInfo.setExtInfo(extInfo);//该字段将会在支付成功后原样返回给CP(不超过500个字符) return payOrderInfo; } private void setSessionInvalidListener(final Activity context){ BDGameSDK.setSessionInvalidListener(new IResponse<Void>(){ @Override public void onResponse(int resultCode, String resultDesc, Void extraData) { if(resultCode == ResultCode.SESSION_INVALID){ login(context); } } }); } private void setSuspendWindowChangeAccountListener(final Activity context){//设置切换账号事件监听(个人中心界面切换账号) BDGameSDK.setSuspendWindowChangeAccountListener(new IResponse<Void>(){ @Override public void onResponse(int resultCode, String resultDesc, Void extraData) { switch(resultCode){ case ResultCode.LOGIN_SUCCESS: //TODO 登录成功,不管之前是什么登录状态,游戏内部都要切换成新的用户 state = SDKState.StateLogined; String token = BDGameSDK.getLoginAccessToken(); U8SDK.getInstance().onResult(U8Code.CODE_LOGIN_SUCCESS, "sid="+";token="+token); LoginResult result = encodeLoginResult( token); U8SDK.getInstance().onLoginResult(result); break; case ResultCode.LOGIN_FAIL: state = SDKState.StateInited; U8SDK.getInstance().onResult(U8Code.CODE_LOGIN_FAIL, "baidu sdk login failed.resultCode:"+resultCode); break; case ResultCode.LOGIN_CANCEL: //TODO 取消,操作前后的登录状态没变化 state = SDKState.StateLogined; U8SDK.getInstance().onResult(U8Code.CODE_LOGIN_FAIL, "baidu sdk login canceled.resultCode:"+resultCode); break; } } }); } public boolean isInited(){ return this.state.ordinal() >= SDKState.StateInited.ordinal(); } } |
到此百度SDK的代码接入工作就算完成了。接下来,我们需要做两个配置。sdk_config.xml和sdk_manifest.xml。我们先在工程的根目录下定义一个sdk_config.xml文件,文件内容如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<?xml version= "1.0" encoding ="UTF-8"?> <config> <params > <param name= "AppID" value ="3067515" bWriteInClient="1" /> <param name= "AppKey" value ="f3Os4GAOqxgm79GqbnkT9L8T" bWriteInClient="1" /> <param name= "Domain" value ="RELEASE" bWriteInClient="1" /> <param name= "BDPlatformType" value ="0" bWriteInManifest= "1"/> <param name= "BDGameVersion" value ="3.1.3" bWriteInManifest= "1"/> </params > <ops > <op step= "1" type ="merge" from="sdk_manifest.xml" to= "AndroidManifest.xml" /> <op step= "2" type ="copy" from="assets" to= "assets" /> <op step= "3" type ="copy" from="libs" to= "lib" /> <op step= "4" type ="copy" from="res" to= "res" /> </ops > <supports > <comp name= "com.u8.sdk.BaiduUser" type ="1" desc="用户登录"/> <comp name= "com.u8.sdk.BaiduPay" type ="2" desc="用户支付"/> </supports > </config> |
这就是一个普通的xml文件,里面分为三个部分:params,ops,supports。
params里面定义的是渠道的参数,name是参数的名称,你可以任意定义,只要在BaiduSDK单例类里面parseSDKParams方法里面解析的时候和这里一一对应就可以了。
value就是参数对应的值了。那么你还看到两个参数。一个是bWriteInClient一个是bWriteInMenifest。
如果bWriteInClient=”1″或者你既没有配置bWriteInClient也没有配置bWriteInManifest,那么该条参数就会被打包工具写入到assets目录下的develop_config.properties文件中。而如果你配置了bWriteInManifest=”1″;那么该条参数就会被打包工具写入到AndroidManifest.xml中application节点下的meta-data里面.关于这两个参数的设计,可以参考之前的博客: 越空之门
为什么要有这两个区别呢?那是因为有些渠道要求必须将某些参数配置到AndroidManifest.xml的meta-data中。而某些参数就是自己配置。
通过这种方式,你在配置参数的时候,就无需将他们分开,直接配置在sdk_config.xml里面,通过bWriteInClient和bWriteInManifest来根据要求选择配置到哪里即可。
第二部分是ops。这里配置了打包工具在打包过程中,需要进行的一些操作。type=”merge”,就是指文件的合并。这里配置的是将sdk_manifest.xml合并到最终的AndroidMainifest.xml中。而type=”copy”,则指的是将from对应的文件夹或者文件拷贝到to指定的最终的反编译目录下的文件夹或者文件。
第三部分是supports。这里定义的是当前这个渠道SDK支持哪些插件。这里name配置插件实现类的完整类名。我们之前实现了用户插件和支付插件。所以这里我们配置一个BaiduUser和BaiduPay。其中type是固定的,1表示用户插件;2表示支付插件。
这些参数的定义在U8SDK的抽象层中。具体渠道在运行的时候,抽象层就是根据该配置里面的name属性,根据java里面的反射Class.forName来实例化具体的插件类。具体的实现你可以参考U8SDK抽象层代码。打包工具在打包的时候,会将supports中配置的插件写入到assets目录下的plugin_config.xml文件。
所以,可以看到,sdk_config.xml这个配置,就是为打包工具准备的。打包工具会根据该配置完成该渠道的打包工作。
下面,我们再来看看sdk_manifest.xml。百度SDK对应的文件内容如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 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 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 |
<?xml version= "1.0" encoding ="UTF-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" > <permissionConfig > <uses-permission android:name="android.permission.SEND_SMS" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.WRITE_SETTINGS" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.GET_TASKS" /> <uses-permission android:name="android.permission.CALL_PHONE" /> <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> <!-- ↑↑↑ SDK ↑↑↑ --> <!-- ↓↓↓ DK SDK ↓↓↓ --> <uses-permission android:name="android.permission.RECEIVE_SMS" /> <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.ACCESS_DOWNLOAD_MANAGER" /> <uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" /> <uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.FLASHLIGHT" /> <uses-permission android:name="android.permission.DISABLE_KEYGUARD" /> <uses-permission android:name="android.permission.BROADCAST_STICKY" /> </permissionConfig > <applicationConfig keyword="com.baidu.platformsdk.LoginActivity" proxyApplication="com.u8.sdk.BaiduApplication" > <activity android:name="com.baidu.platformsdk.LoginActivity" android:configChanges="orientation|navigation|screenSize|keyboard|keyboardHidden" android:exported="false" android:excludeFromRecents="true" android:theme="@style/bdp_dialog_style_fullscreen" /> <activity android:name="com.baidu.platformsdk.AssistActivity" android:configChanges="orientation|navigation|screenSize|keyboard|keyboardHidden" android:exported="false" android:excludeFromRecents="true" android:theme="@style/bdp_dialog_style_fullscreen" /> <activity android:name="com.baidu.platformsdk.BindPhoneActivity" android:configChanges="orientation|navigation|screenSize|keyboard|keyboardHidden" android:exported="false" android:excludeFromRecents="true" android:theme="@style/bdp_dialog_style_fullscreen" /> <activity android:name="com.baidu.platformsdk.CashierDeskActivity" android:configChanges="orientation|navigation|screenSize|keyboard|keyboardHidden" android:exported="false" android:theme="@style/bdp_dialog_style_fullscreen" android:windowSoftInputMode="adjustPan" /> <activity android:name="com.baidu.platformsdk.WebActivity" android:configChanges="orientation|navigation|screenSize|keyboard|keyboardHidden" android:exported="false" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:windowSoftInputMode="adjustPan" /> <activity android:name="com.baidu.platformsdk.ModifyPasswordActivity" android:configChanges="orientation|navigation|screenSize|keyboard|keyboardHidden" android:exported="false" android:excludeFromRecents="true" android:theme="@style/bdp_dialog_style_fullscreen" /> <activity android:name="com.baidu.platformsdk.ThirdPartyLoginActivity" android:configChanges="orientation|navigation|screenSize|keyboard|keyboardHidden" android:excludeFromRecents="true" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:exported="false" /> <activity android:name="com.baidu.platformsdk.VisitorBindActivity" android:configChanges="orientation|navigation|screenSize|keyboard|keyboardHidden" android:exported="false" android:excludeFromRecents="true" android:theme="@style/bdp_dialog_style_fullscreen" /> <activity android:name="com.baidu.platformsdk.BaiduBeanDetailActivity" android:configChanges="orientation|navigation|screenSize|keyboard|keyboardHidden" android:exported="false" android:windowSoftInputMode="adjustPan" android:theme="@style/bdp_dialog_style_fullscreen" /> <activity android:name="com.baidu.platformsdk.OrderDetailActivity" android:configChanges="orientation|navigation|screenSize|keyboard|keyboardHidden" android:exported="false" android:windowSoftInputMode="adjustPan" android:theme="@style/bdp_dialog_style_fullscreen" /> <activity android:name="com.baidu.platformsdk.TaskActivity" android:configChanges="orientation|navigation|screenSize|keyboard|keyboardHidden" android:exported="false" android:windowSoftInputMode="adjustPan" android:theme="@style/bdp_dialog_style_fullscreen" /> <service android:name="com.baidu.platformsdk.BDPlatformService" android:exported="false" /> <!-- ↑↑↑ SDK ↑↑↑ --> <!-- ↓↓↓ 百度钱包 ↓↓↓ --> <activity android:name="com.baidu.android.pay.ui.WelcomeActivity" android:configChanges="keyboardHidden|navigation|orientation|screenSize" android:excludeFromRecents="true" android:exported="false" android:theme="@style/EbpayThemeActivityWelcome" android:windowSoftInputMode="stateHidden" /> <activity android:name="com.baidu.android.pay.ui.PayResultActivity" android:configChanges="keyboardHidden|navigation|orientation|screenSize" android:excludeFromRecents="true" android:exported="false" android:theme="@style/EbpayThemeActivit" android:windowSoftInputMode="stateHidden" > </activity> <activity android:name="com.baidu.android.pay.ui.PwdCheckActivity" android:configChanges="keyboardHidden|navigation|orientation|screenSize" android:excludeFromRecents="true" android:exported="false" android:theme="@style/EbpayThemeActivit" android:windowSoftInputMode="stateVisible" > </activity> <activity android:name="com.baidu.android.pay.ui.PwdSetActivity" android:configChanges="keyboardHidden|navigation|orientation|screenSize" android:excludeFromRecents="true" android:exported="false" android:theme="@style/EbpayThemeActivit" android:windowSoftInputMode="stateVisible" > </activity> <activity android:name="com.baidu.android.pay.ui.PwdConfirmActivity" android:configChanges="keyboardHidden|navigation|orientation|screenSize" android:excludeFromRecents="true" android:exported="false" android:theme="@style/EbpayThemeActivit" android:windowSoftInputMode="stateVisible" > </activity> <activity android:name="com.baidu.android.pay.ui.PwdPayActivity" android:configChanges="keyboardHidden|navigation|orientation|screenSize" android:excludeFromRecents="true" android:exported="false" android:theme="@style/EbpayThemeActivitTranslucent" android:windowSoftInputMode="stateVisible" /> <activity android:name="com.baidu.android.pay.ui.PwdPaySmsActivity" android:configChanges="keyboardHidden|navigation|orientation|screenSize" android:excludeFromRecents="true" android:exported="false" android:theme="@style/EbpayThemeActivitTranslucent" android:windowSoftInputMode="stateHidden" /> <activity android:name="com.baidu.android.pay.ui.WebViewActivity" android:configChanges="keyboardHidden|navigation|orientation|screenSize" android:excludeFromRecents="true" android:exported="false" android:theme="@style/EbpayThemeActivit" android:windowSoftInputMode="stateHidden" > </activity> <activity android:name="com.baidu.android.pay.ui.BindFirstActivity" android:configChanges="keyboardHidden|navigation|orientation|screenSize" android:excludeFromRecents="true" android:exported="false" android:theme="@style/EbpayThemeActivit" android:windowSoftInputMode="adjustResize" /> <activity android:name="com.baidu.android.pay.ui.BindSecondActivity" android:configChanges="keyboardHidden|navigation|orientation|screenSize" android:excludeFromRecents="true" android:exported="false" android:theme="@style/EbpayThemeActivit" android:windowSoftInputMode="stateHidden" /> <activity android:name="com.baidu.android.pay.ui.BindSecondCreditAcitvity" android:configChanges="keyboardHidden|navigation|orientation|screenSize" android:excludeFromRecents="true" android:exported="false" android:theme="@style/EbpayThemeActivit" android:windowSoftInputMode="stateHidden" /> <activity android:name="com.baidu.android.pay.ui.BindSecondCredit2Activity" android:configChanges="keyboardHidden|navigation|orientation|screenSize" android:excludeFromRecents="true" android:exported="false" android:theme="@style/EbpayThemeActivit" android:windowSoftInputMode="stateHidden" /> <activity android:name="com.baidu.android.pay.ui.BindThirdActivity" android:configChanges="keyboardHidden|navigation|orientation|screenSize" android:excludeFromRecents="true" android:exported="false" android:theme="@style/EbpayThemeActivit" android:windowSoftInputMode="adjustResize" /> <activity android:name="com.baidu.android.pay.ui.SelectBindCardActivity" android:configChanges="keyboardHidden|navigation|orientation|screenSize" android:excludeFromRecents="true" android:exported="false" android:theme="@style/EbpayThemeActivit" android:windowSoftInputMode="stateHidden" /> <activity android:name="com.baidu.android.pay.ui.LoginActivity" android:configChanges="keyboardHidden|navigation|orientation|screenSize" android:excludeFromRecents="true" android:exported="false" android:theme="@style/EbpayThemeActivit" android:windowSoftInputMode="stateHidden" /> <activity android:name="com.baidu.android.pay.ui.PassNormalizeActivity" android:configChanges="keyboardHidden|navigation|orientation|screenSize" android:excludeFromRecents="true" android:exported="false" android:theme="@style/EbpayThemeActivit" android:windowSoftInputMode="stateHidden" /> <activity android:name="com.baidu.android.pay.ui.OrderHomeActivity" android:configChanges="keyboardHidden|navigation|orientation|screenSize" android:excludeFromRecents="true" android:exported="false" android:theme="@style/EbpayThemeActivit" android:windowSoftInputMode="stateHidden" /> <!-- ↑↑↑ 百度钱包 ↑↑↑ --> <!-- ↓↓↓ passport ↓↓↓ --> <activity android:name="com.baidu.sapi2.utils.LoginProtectAcitivity" android:screenOrientation="landscape" android:theme="@style/bdp_SapiTheme" android:windowSoftInputMode="adjustPan" /> <!-- ↑↑↑ passport ↑↑↑ --> <!-- ↓↓↓ 银联SDK ↓↓↓ --> <activity android:name="com.unionpay.uppay.PayActivity" android:screenOrientation="landscape" /> <!-- ↑↑↑ 银联SDK ↑↑↑ --> <!-- ↓↓↓ 支付宝插件 ↓↓↓ --> <activity android:name="com.alipay.sdk.app.H5PayActivity" android:configChanges="orientation|keyboardHidden|navigation" android:exported="false" android:screenOrientation="behind" /> <activity android:name="com.alipay.sdk.auth.AuthActivity" android:configChanges="orientation|keyboardHidden|navigation" android:exported="false" android:screenOrientation="behind" /> <!-- ↑↑↑ 支付宝插件 ↑↑↑ --> <!-- ↓↓↓ 多酷SDK ↓↓↓ --> <activity android:name="com.duoku.platform.ui.DKContainerActivity" android:configChanges="orientation|keyboardHidden|navigation|screenSize" android:launchMode="singleTop" android:theme="@style/StyledIndicators" > </activity> <service android:name="com.duoku.platform.service.DKSuspensionService" /> <!-- 贴吧 start --> <activity android:name="com.baidu.tiebasdk.ext.motu.SelectBarActivity" android:configChanges="orientation|keyboardHidden|navigation" android:process=":remote" /> <activity android:name="com.baidu.tiebasdk.account.InputUserNameActivity" android:configChanges="orientation|keyboardHidden|navigation" android:process=":remote" android:theme="@android:style/Theme.Translucent.NoTitleBar" > <intent-filter> </intent-filter> </activity> <activity android:name="com.baidu.tiebasdk.account.LoginActivity" android:configChanges="orientation|keyboardHidden|navigation" android:process=":remote" > <intent-filter> </intent-filter> </activity> <activity android:name="com.baidu.tiebasdk.account.Register2Activity" android:configChanges="orientation|keyboardHidden|navigation" android:process=":remote" > <intent-filter> </intent-filter> </activity> <activity android:name="com.baidu.tiebasdk.account.ActivationActivity" android:configChanges="orientation|keyboardHidden|navigation" android:process=":remote" > <intent-filter> </intent-filter> </activity> <activity android:name="com.baidu.tiebasdk.account.ProtocolActivity" android:configChanges="orientation|keyboardHidden|navigation" android:process=":remote" > <intent-filter> </intent-filter> </activity> <activity android:name="com.baidu.tiebasdk.frs.FrsActivity" android:configChanges="orientation|keyboardHidden|navigation" android:process=":remote" > </activity> <activity android:name="com.baidu.tiebasdk.frs.FrsImageActivity" android:configChanges="orientation|keyboardHidden|navigation" android:process=":remote" > </activity> <activity android:name="com.baidu.tiebasdk.mention.MentionActivity" android:configChanges="orientation|keyboardHidden|navigation" android:process=":remote" > <intent-filter> </intent-filter> </activity> <activity android:name="com.baidu.tiebasdk.mention.ReplyMeActivity" android:configChanges="orientation|keyboardHidden|navigation" android:process=":remote" > <intent-filter> </intent-filter> </activity> <activity android:name="com.baidu.tiebasdk.mention.AtMeActivity" android:configChanges="orientation|keyboardHidden|navigation" android:process=":remote" > <intent-filter> </intent-filter> </activity> <activity android:name="com.baidu.tiebasdk.pb.NewPbActivity" android:configChanges="orientation|keyboardHidden|navigation" android:process=":remote" android:windowSoftInputMode="adjustResize|stateHidden" > <intent-filter> </intent-filter> </activity> <activity android:name="com.baidu.tiebasdk.pb.ImagePbActivity" android:configChanges="orientation|keyboardHidden|navigation" android:process=":remote" android:windowSoftInputMode="adjustResize" > <intent-filter> </intent-filter> </activity> <activity android:name="com.baidu.tiebasdk.write.WriteActivity" android:configChanges="orientation|keyboardHidden|navigation" android:process=":remote" android:windowSoftInputMode="stateVisible|adjustResize" > <intent-filter> </intent-filter> </activity> <activity android:name="com.baidu.tiebasdk.write.VcodeActivity" android:configChanges="orientation|keyboardHidden|navigation" android:process=":remote" android:windowSoftInputMode="stateVisible|adjustResize" > <intent-filter> </intent-filter> </activity> <activity android:name="com.baidu.tiebasdk.write.NewVcodeActivity" android:configChanges="orientation|keyboardHidden|navigation" android:process=":remote" android:windowSoftInputMode="stateHidden" > <intent-filter> </intent-filter> </activity> <activity android:name="com.baidu.tiebasdk.write.AtListActivity" android:configChanges="orientation|keyboardHidden|navigation" android:process=":remote" > <intent-filter> </intent-filter> </activity> <activity android:name="com.baidu.tiebasdk.write.WriteImageActivity" android:configChanges="orientation|keyboardHidden|navigation" android:process=":remote" > <intent-filter> </intent-filter> </activity> <activity android:name="com.baidu.tiebasdk.pb.ImageActivity" android:configChanges="orientation|keyboardHidden|navigation" android:process=":remote" > <intent-filter> </intent-filter> </activity> <activity android:name="com.baidu.tiebasdk.pb.WebActivity" android:configChanges="orientation|keyboardHidden|navigation" android:process=":remote" > <intent-filter> </intent-filter> </activity> <activity android:name="com.baidu.tiebasdk.more.AccountActivity" android:process=":remote" > <intent-filter> </intent-filter> </activity> <!-- 贴吧activity end --> <!-- 贴吧 service begin --> <service android:name="com.baidu.tiebasdk.service.TiebaUpdateService" android:enabled="true" android:process=":remote" > <intent-filter> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </service> <service android:name="com.baidu.tiebasdk.service.TiebaFullUpdateService" android:enabled="true" android:process=":remote" > <intent-filter> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </service> <service android:name="com.baidu.tiebasdk.service.ClearTempService" android:enabled="true" android:process=":remote" > <intent-filter> <category android:name="android.intent.category.DEFAULT" android:process=":remote" /> </intent-filter> </service> <service android:name="com.baidu.tiebasdk.service.FatalErrorService" android:enabled="true" android:process=":remote" > <intent-filter> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </service> <service android:name="com.baidu.tiebasdk.service.TiebaSyncService" android:enabled="true" android:process=":remote" > <intent-filter> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </service> <service android:name="com.baidu.tiebasdk.service.TiebaMessageService" android:enabled="true" android:process=":remote" > <intent-filter> <action android:name="com.baidu.tiebasdk.service.Message" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </service> <service android:name="com.baidu.tiebasdk.service.TiebaPrepareImageService" android:enabled="true" android:process=":remote" > <intent-filter> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </service> <!-- 贴吧 service end --> <!-- push service client --> <receiver android:name="com.duoku.platform.push.MyReceiver" > <intent-filter> <action android:name="com.duoku" /> </intent-filter> </receiver> <receiver android:name="com.duoku.platform.push.PushMessageReceiver" > <intent-filter> <!-- 接收push消息 --> <action android:name="com.baidu.android.pushservice.action.MESSAGE" /> <!-- 接收bind,unbind,fetch,delete等反馈消息 --> <action android:name="com.baidu.android.pushservice.action.RECEIVE" /> <action android:name="com.baidu.android.pushservice.action.notification.CLICK" /> </intent-filter> </receiver> <receiver android:name="com.baidu.android.pushservice.PushServiceReceiver" android:process=":bdservice_v1" > <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> <action android:name="com.baidu.android.pushservice.action.notification.SHOW" /> <action android:name="com.baidu.android.pushservice.action.media.CLICK" /> </intent-filter> </receiver> <receiver android:name="com.baidu.android.pushservice.RegistrationReceiver" android:process=":bdservice_v1" > <intent-filter> <action android:name="com.baidu.android.pushservice.action.METHOD" /> <action android:name="com.baidu.android.pushservice.action.BIND_SYNC" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.PACKAGE_REMOVED" /> <data android:scheme="package" /> </intent-filter> </receiver> <service android:name="com.baidu.android.pushservice.PushService" android:exported="true" android:process=":bdservice_v1" /> <!-- push service end --> <!-- 贴吧 receiver start --> <receiver android:name="com.baidu.tiebasdk.service.TiebaReceiver" android:process=":remote" > <intent-filter> <action android:name="com.baidu.tiebasdk.broadcast.service" /> <action android:name="com.baidu.tiebasdk.broadcast.sync" /> </intent-filter> </receiver> <receiver android:name="com.baidu.tiebasdk.service.InstallReceiver" android:process=":remote" > <intent-filter> <action android:name="android.intent.action.PACKAGE_ADDED" /> <action android:name="android.intent.action.PACKAGE_REMOVED" /> <data android:scheme="package" /> </intent-filter> </receiver> <receiver android:name="com.baidu.tiebasdk.service.SyncLoginReceiverForAs" android:process=":remote" > <intent-filter> <action android:name="com.baidu.tiebasdk.broadcast.syncLoginFromAS" /> </intent-filter> </receiver> <!-- 贴吧 receiver end --> <!-- ↑↑↑ 多酷SDK ↑↑↑ --> </applicationConfig > </manifest> |
可以看到这也就是一个普通的xml配置文件。有两大节点。permissionConfig和applicationConfig。permissionConfig节点下就是配置该渠道所需要的权限信息;applicationConfig节点下,就是配置渠道SDK需要在AndroidManfiest.xml的application节点下配置的所有信息。
打包工具在合并的时候,也就是将permissionConfig下的权限信息合并到AndroidManifest.xml的权限中。将applicationConfig节点下所有的内容添加到AndroidManfiest.xml的application节点下。
需要注意下的就是,在applicationConfig节点上,我们定义了两个属性。一个是keyword,一个是proxyApplication.keyword原本是用来查重的。但是作用不大,一般不会出现重复。配置时可以直接配置成渠道SDK第一个activity或者service等的名字。当然你不配置也可以。
而proxyApplication是某些渠道需要在Application的生命周期方法中去做些操作。所以,在u8sdk中我们之前就已经实现了关于application这块的设计。你可以参考之前的博客: 逆空穿梭。
这两个文件定义好之后,我们就可以到打包工具目录下去添加该渠道的配置了。
1、首先到打包工具目录下sdks/sdk目录下新建一个唯一名称的文件夹。我们这里叫baidu
2、然后我们在baidu目录下新建三个子目录,assets,libs,res.这三个子目录分别对应我们之前在sdk_config.xml中ops节点中配置的from目录。
3、我们去百度提供的SDK目录下,看看他需要将哪些资源放在assets目录中,哪些资源需要放在res下,哪些资源需要放在libs中。
3.1:没有需要放在assets目录中的资源。
3.2: 将百度提供的res资源文件夹下的所有内容拷贝到baidu/res目录下。
3.3:将百度提供的libs目录下的依赖的文件拷贝到baidu/libs目录下。注意,libs目录下,我们不需要拷贝.jar文件,仅仅把除了.jar文件
的所有其他.so文件或者文件夹拷贝到libs目录下即可。
然后assets目录下是空的,res目录和libs目录下内容分别如下图:
4、我们回到eclipse中的U8SDK_Baidu工程,右键->Run as->Android Application.然后在该工程的bin目录下你会看到生成了一些文件,其中有一个classes.dex文件。
我们这里run的目的不是为了生成apk包,仅仅是为了生成classes.dex文件。这个时候生成的apk包,安装到手机也是运行不起来的。该classes.dex文件里面已经包含所有libs目录下的jar包。所以上一步操作,我们无需拷贝.jar文件。
然后,我们将该classes.dex文件,以及我们之前创建的sdk_config.xml和sdk_manifest.xml文件一起拷贝到打包工具中我们刚创建的baidu目录下。
注意:如果你重复步骤4,在操作之前你需要在eclipse顶部的菜单栏中选择Project->Clean 然后Clean一下该工程。Clean的作用就是清空bin目录下的内容,然后你重新RunAs一下,又会重新在bin目录下生成classes.dex文件了。
现在打包工具中sdks/sdk/baidu目录下就是这个样子:
5、到第四步就已经配置完毕了,那么我们怎么用打包功能来出包测试呢。我们在sdks目录下有一个config.xml这个文件就是配置当前需要打包的渠道。在该配置中增加上我们刚刚实现的baidu渠道SDK的配置即可。
6、然后你就可以运行U8SDKPacker目录下的pack_debug.bat文件开始打包了。打包完毕在packages目录下会生成一个baidu文件夹,这里就是最终的渠道包了。
好了,到这里你应该对u8sdk中接入新渠道的流程有了八九成的了解。如果还有啥不明白的可以QQ私聊我(2848004717)或者欢迎加入U8SDK交流群(207609068)
请记住,这里是u8sdk的官方网站:http://www.uustory.com
本文出自 U8SDK技术博客,转载时请注明出处及相应链接。
本文永久链接: http://www.uustory.com/?p=1619