zoukankan      html  css  js  c++  java
  • 腾讯x5内核集成和下载

    1,集成

    从官网下载最新集成包http://res.imtt.qq.com/TES/tbssdk_43903_1586765647646.zip,里面包含有jar、so库,引入项目

    2,继承腾讯的webView,并重新实现一些方法

    package com.example;
    
    import android.annotation.SuppressLint;
    import android.content.Context;
    import android.graphics.Canvas;
    import android.graphics.Paint;
    import android.os.Build;
    import android.util.AttributeSet;
    import android.view.View;
    import android.widget.TextView;
    
    import com.tencent.smtt.sdk.QbSdk;
    import com.tencent.smtt.sdk.WebSettings;
    import com.tencent.smtt.sdk.WebView;
    import com.tencent.smtt.sdk.WebViewClient;
    
    public class X5WebView extends WebView {
            TextView title;
            private WebViewClient client = new WebViewClient() {
                /**
                 * 防止加载网页时调起系统浏览器
                 */
                public boolean shouldOverrideUrlLoading(WebView view, String url) {
                    view.loadUrl(url);
                    return true;
                }
            };
    
            @SuppressLint("SetJavaScriptEnabled")
            public X5WebView(Context arg0, AttributeSet arg1) {
                super(arg0, arg1);
                this.setWebViewClient(client);
                // this.setWebChromeClient(chromeClient);
                // WebStorage webStorage = WebStorage.getInstance();
                initWebViewSettings();
                this.getView().setClickable(true);
            }
    
            private void initWebViewSettings() {
                WebSettings webSetting = this.getSettings();
                webSetting.setJavaScriptEnabled(true);
                webSetting.setJavaScriptCanOpenWindowsAutomatically(true);
                webSetting.setAllowFileAccess(true);
                webSetting.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
                webSetting.setSupportZoom(true);
                webSetting.setBuiltInZoomControls(true);
                webSetting.setUseWideViewPort(true);
                webSetting.setSupportMultipleWindows(true);
                // webSetting.setLoadWithOverviewMode(true);
                webSetting.setAppCacheEnabled(true);
                // webSetting.setDatabaseEnabled(true);
                webSetting.setDomStorageEnabled(true);
                webSetting.setGeolocationEnabled(true);
                webSetting.setAppCacheMaxSize(Long.MAX_VALUE);
                // webSetting.setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY);
                webSetting.setPluginState(WebSettings.PluginState.ON_DEMAND);
                // webSetting.setRenderPriority(WebSettings.RenderPriority.HIGH);
                webSetting.setCacheMode(WebSettings.LOAD_NO_CACHE);
    
                // this.getSettingsExtension().setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY);//extension
                // settings 的设计
            }
    
            @Override
            protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
                boolean ret = super.drawChild(canvas, child, drawingTime);
                canvas.save();
                Paint paint = new Paint();
                paint.setColor(0x7fff0000);
                paint.setTextSize(24.f);
                paint.setAntiAlias(true);
                if (getX5WebViewExtension() != null) {
                    canvas.drawText(this.getContext().getPackageName() + "-pid:"
                            + android.os.Process.myPid(), 10, 50, paint);
                    canvas.drawText(
                            "X5  Core:" + QbSdk.getTbsVersion(this.getContext()), 10,
                            100, paint);
                } else {
                    canvas.drawText(this.getContext().getPackageName() + "-pid:"
                            + android.os.Process.myPid(), 10, 50, paint);
                    canvas.drawText("Sys Core", 10, 100, paint);
                }
                canvas.drawText(Build.MANUFACTURER, 10, 150, paint);
                canvas.drawText(Build.MODEL, 10, 200, paint);
                canvas.restore();
                return ret;
            }
    
            public X5WebView(Context arg0) {
                super(arg0);
                setBackgroundColor(85621);
            }
    
    }
    

      

    3,activity的xml文件添加webView

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="match_parent">
    <com.example.X5WebView
        android:id="@+id/x5webView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />
    </LinearLayout>
    

      

    4,application中初始化腾讯的x5WebView

    QbSdk.initX5Environment(getApplicationContext(), new QbSdk.PreInitCallback() {
        @Override
        public void onCoreInitFinished() {
            Log.d(TAG,"onCoreInitFinished ");
        }
        @Override
        public void onViewInitFinished(boolean b) {
            LogUtils.dTag(TAG,"onViewInitFinished flag = "+b);
            Log.d(TAG,"onViewInitFinished flag = "+b);
        }
    });
    QbSdk.setDownloadWithoutWifi(true);//不是weifi也下载x5内核,但是感觉不起作用
    

      

    5,如果加载的时候,发现不是走的webView,可以设置webview加载debugtbs.qq.com,安装线上内核,然后会自动重启app,再次用webview加载url时,就是x5内核的了,也可以在debugtbs.qq.com查询内核版本号

    ps:个人感觉最好是把tbs放到工程中,然后使用webview之前先进行安装,然后再使用

  • 相关阅读:
    【存储过程】输入学生的姓名,打印出学生的最高分、最低分、平均分
    Oracle序列Sequence用法
    Oracle数据库正则表达式
    Oracle数据库添加约束
    CVX使用手册翻译
    波束赋形技术
    IRS与物理层安全
    5G关键技术总结
    2019年研究生数学建模竞赛
    2019年华为软挑总结
  • 原文地址:https://www.cnblogs.com/fengchuxiaodai/p/13132484.html
Copyright © 2011-2022 走看看