| | |
| | | package cn.flightfeather.thirdappmodule.util.tbs |
| | | |
| | | import android.content.Context |
| | | import android.util.Log |
| | | import com.tencent.smtt.sdk.QbSdk |
| | | |
| | | import com.tencent.smtt.sdk.TbsDownloader |
| | | import com.tencent.smtt.sdk.TbsListener |
| | | |
| | | |
| | | /** |
| | |
| | | class Tbs { |
| | | |
| | | companion object { |
| | | private const val TAG = "Tbs" |
| | | |
| | | fun init(applicationContext: Context) { |
| | | //搜集本地tbs内核信息并上报服务器,服务器返回结果决定使用哪个内核。 |
| | |
| | | override fun onViewInitFinished(arg0: Boolean) { |
| | | // TODO Auto-generated method stub |
| | | //x5內核初始化完成的回调,为true表示x5内核加载成功,否则表示x5内核加载失败,会自动切换到系统内核。 |
| | | |
| | | println("QbSdk.initX5Environment---$arg0") |
| | | } |
| | | |
| | | override fun onCoreInitFinished() { |
| | | // TODO Auto-generated method stub |
| | | println("QbSdk.initX5Environment---finished") |
| | | } |
| | | } |
| | | //x5内核初始化接口 |
| | | QbSdk.setDownloadWithoutWifi(true) |
| | | |
| | | /* SDK内核初始化周期回调,包括 下载、安装、加载 */ |
| | | QbSdk.setTbsListener(object : TbsListener { |
| | | /** |
| | | * @param stateCode 用户可处理错误码请参考[com.tencent.smtt.sdk.TbsCommonCode] |
| | | */ |
| | | override fun onDownloadFinish(stateCode: Int) { |
| | | Log.i(TAG, "onDownloadFinished: $stateCode") |
| | | } |
| | | |
| | | /** |
| | | * @param stateCode 用户可处理错误码请参考[com.tencent.smtt.sdk.TbsCommonCode] |
| | | */ |
| | | override fun onInstallFinish(stateCode: Int) { |
| | | Log.i(TAG, "onInstallFinished: $stateCode") |
| | | } |
| | | |
| | | /** |
| | | * 首次安装应用,会触发内核下载,此时会有内核下载的进度回调。 |
| | | * @param progress 0 - 100 |
| | | */ |
| | | override fun onDownloadProgress(progress: Int) { |
| | | Log.i(TAG, "Core Downloading: $progress") |
| | | } |
| | | }) |
| | | |
| | | val needDownLoad = TbsDownloader.needDownload(applicationContext, TbsDownloader.DOWNLOAD_OVERSEA_TBS) |
| | | if (needDownLoad) { |
| | | TbsDownloader.startDownload(applicationContext) |
| | | } |
| | | |
| | | QbSdk.initX5Environment(applicationContext, cb) |
| | | } |
| | | } |