テンセントX 5カーネルwebViewは統合使用です


テンセントX 5の公式文書:http://x5.tencent.com/最新のSDK Android studioの統合方法をダウンロード:まず:腾讯X5内核webView的是集成使用_第1张图片
sdkを初期化し、自分のApplicationで初期化し、初期化は時間のかかる操作であり、サブスレッドで実行することが望ましい.
public class MyApplication extends Application {

    private static MyApplication mInStance = null;
    @Override
    public void onCreate() {
        super.onCreate();
        mInStance = this;
        initX5();
    }

    private void initX5() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                QbSdk.initX5Environment(MyApplication.getInstace().getApplicationContext(),new QbSdk.PreInitCallback(){
                    @Override
                    public void onCoreInitFinished() {

                    }

                    @Override
                    public void onViewInitFinished(boolean arg0) {
                        //       true   x5      。     x5       
                        Log.e("zz", " onViewInitFinished is " + arg0);
                    }
                });
            }
        }).start();
    }

    public static MyApplication getInstace (){

        return mInStance;
    }
}

第三歩:X 5 WebViewをカスタマイズし、テンセントsdkのwebViewを統合する
public class X5WebView extends WebView {
    public X5WebView (Context context){
        super(context);
        setBackgroundColor(85621);
    }

    private WebViewClient client = new WebViewClient(){
     //              
        @Override
        public boolean shouldOverrideUrlLoading(WebView webView, String url) {
            webView.loadUrl(url);
            return true;
        }
    };


    @SuppressLint("SetJavaScriptEnabled")
    public X5WebView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.setWebViewClient(client);
        initWebViewSettings();
        this.getView().setClickable(true);

    }

    private void initWebViewSettings() {
       WebSettings mWebviewSettings = this.getSettings();
        mWebviewSettings.setJavaScriptEnabled(true);
        mWebviewSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        mWebviewSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
        mWebviewSettings.setSupportZoom(true);
        mWebviewSettings.setBuiltInZoomControls(true);//       
        mWebviewSettings.setUseWideViewPort(true);//       
        mWebviewSettings.setSupportMultipleWindows(true);
        mWebviewSettings.setAppCacheEnabled(true);
        mWebviewSettings.setDomStorageEnabled(true);//  localStorage
        mWebviewSettings.setGeolocationEnabled(true);
        mWebviewSettings.setSaveFormData(true);//      
        mWebviewSettings.setAllowFileAccess(true);//      
        mWebviewSettings.setAppCacheMaxSize(Long.MAX_VALUE);
        mWebviewSettings.setPluginState(WebSettings.PluginState.ON_DEMAND);
        mWebviewSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    }


}

Activityでのwebviewの使用
public class MainActivity extends AppCompatActivity {
    private X5WebView webView;
    private ValueCallback uploadFile;
    private ValueCallback uploadFiles;

    private Context context;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        context = this;
        findview();
        initWebView();


    }

    private void findview() {
        webView = findViewById(R.id.web_filechooser);

        FadingCircle fadingCircle = new FadingCircle();
        progressBar.setIndeterminateDrawable(fadingCircle);

    }

    private void initWebView() {
        webView.setWebViewClient(new WebViewClient() {
            public void OpenfileChooser(ValueCallback uploadMsg) {
                MainActivity.this.uploadFile = uploadMsg;
                openFileChooseProcess();
            }

            public void OpenfileChooser(ValueCallback uploadMsg, String acceptType) {
                MainActivity.this.uploadFile = uploadMsg;

                openFileChooseProcess();
            }

            public void OpenfileChooser(ValueCallback uploadMsg, String acceptType, String capture) {
                MainActivity.this.uploadFile = uploadMsg;
                openFileChooseProcess();
            }

            public boolean OnShowfileChooser(com.tencent.smtt.sdk.WebView webView,
                                             ValueCallback filepathcallback,
                                             WebChromeClient.FileChooserParams fileChooserParams
            ) {

                MainActivity.this.uploadFiles = filepathcallback;
                openFileChooseProcess();
                return true;
            }
        });

        webView.getSettings().setUseWideViewPort(true);//       
        webView.loadUrl("http://mp.weixin.qq.com/s/MSi8Paouora1JNT-qdQcKg");

        webView.setWebViewClient(new WebViewClient() {


            @Override
            public void onPageFinished(WebView webView, String s) {
                super.onPageFinished(webView, s);
                webView.evaluateJavascript("document.getElementsByTagName('body')[0].getElementsByClassName('kz-float-layer bottom')[0].remove();",
                        new ValueCallback() {
                        //         
                            @Override
                            public void onReceiveValue(String s) {
                                Log.e("zz", s);

                            }
                        });

            }


            @Override
            public void onPageStarted(WebView webView, String s, Bitmap bitmap) {
                super.onPageStarted(webView, s, bitmap);
            }
        });
        webView.setWebChromeClient(new WebChromeClient() {
            //    
            @Override
            public void onProgressChanged(WebView webView, int i) {
                super.onProgressChanged(webView, i);
                Log.e("zz", String.valueOf(i));
            }
        });


    }

    public boolean onKeyDown(int keyCode, KeyEvent keyEvent) {

        if (keyCode == KeyEvent.KEYCODE_BACK && webView.canGoBack()) {
            webView.goBack();
            return true;
        } else {
            finish();
            return true;
        }
    }


    private void openFileChooseProcess() {

        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("*/*");
        startActivityForResult(Intent.createChooser(intent, "test"), 0);


    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
                case 0:
                    if (null != uploadFile) {
                        Uri result = data == null || resultCode != RESULT_OK ? null
                                : data.getData();
                        uploadFile.onReceiveValue(result);
                        uploadFile = null;
                    }
                    if (null != uploadFiles) {
                        Uri result = data == null || resultCode != RESULT_OK ? null
                                : data.getData();
                        uploadFiles.onReceiveValue(new Uri[]{result});
                        uploadFiles = null;
                    }
                    break;
                default:
                    break;
            }

        } else if (resultCode == RESULT_CANCELED) {
            if (null != uploadFile) {
                uploadFile.onReceiveValue(null);
                uploadFile = null;
            }

        }
    }


    @Override
    protected void onDestroy() {
        if (this.webView  != null){
            webView.destroy();
        }
        super.onDestroy();

    }
}

xml
"http://schemas.android.com/apk/res/android"
    android:id="@+id/main_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

     <com.zsdl.x5tbs.util.X5WebView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/web_filechooser"
        >
      com.zsdl.x5tbs.util.X5WebView>

最後にmainfestに権限を追加する
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.READ_SETTINGS" />
    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

参照先:https://blog.csdn.net/qq_36480491/article/details/77882707?skintest=skin3-template-test https://blog.csdn.net/EUEHEUEN/article/details/79414551