xwalk内核集成
aar下载地址:https://download.01.org/crosswalk/releases/crosswalk/android/maven2/org/xwalk/xwalk_core_library/
集成步骤:
1,aar引入项目
implementation files('libs\\xwalk_core_library-23.53.589.4-arm.aar')
2,布局添加XWalkView
<org.xwalk.core.XWalkView android:id="@+id/xwalkview" android:layout_width="match_parent" android:layout_height="match_parent"> </org.xwalk.core.XWalkView>
3,activity继承XWalkActivity,并且在onXWalkReady()方法内或者之后进行XWalkView的设置和加载url动作
package com.example; import android.net.http.SslError; import android.os.Bundle; import android.support.annotation.Nullable; import android.webkit.ValueCallback; import com.example.h5demox5.R; import org.xwalk.core.ClientCertRequest; import org.xwalk.core.XWalkActivity; import org.xwalk.core.XWalkHttpAuthHandler; import org.xwalk.core.XWalkJavascriptResult; import org.xwalk.core.XWalkResourceClient; import org.xwalk.core.XWalkSettings; import org.xwalk.core.XWalkUIClient; import org.xwalk.core.XWalkView; import org.xwalk.core.XWalkWebResourceRequest; import org.xwalk.core.XWalkWebResourceResponse; public class xWalkWebActivity extends XWalkActivity { XWalkView mXWalkView; @Override protected void onXWalkReady() { XWalkSettings mWebSettings = mXWalkView.getSettings(); mWebSettings.setSupportZoom(true);//支持缩放 mWebSettings.setBuiltInZoomControls(true);//可以任意缩放 mWebSettings.setLoadWithOverviewMode(true); mWebSettings.setUseWideViewPort(true);////将图片调整到适合webview的大小 // mWebSettings.setDefaultTextEncodingName("utf-8"); mWebSettings.setLoadsImagesAutomatically(true); // mWebSettings.setMixedContentMode() //调用JS方法.安卓版本大于17,加上注解 @JavascriptInterface mWebSettings.setJavaScriptEnabled(true);//支持JS mWebSettings.setCacheMode(mWebSettings.LOAD_NO_CACHE); mXWalkView.setResourceClient( new XWalkResourceClient(mXWalkView) { //=========HTML5定位========================================================== //需要先加入权限 //<uses-permission android:name="android.permission.INTERNET"/> //<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> //<uses-permission android:name= // "android.permission.ACCESS_COARSE_LOCATION"/> @Override public boolean shouldOverrideUrlLoading(XWalkView view, String url) { view.loadUrl(url); return true; } @Override public void onReceivedSslError(XWalkView view, ValueCallback<Boolean> callback, SslError error) { super.onReceivedSslError(view, callback, error); } @Override public void onLoadFinished(XWalkView view, String url) { super.onLoadFinished(view, url); } @Override public void onLoadStarted(XWalkView view, String url) { super.onLoadStarted(view, url); } @Override public void onProgressChanged(XWalkView view, int progressInPercent) { super.onProgressChanged(view, progressInPercent); } @Override public void onReceivedClientCertRequest(XWalkView view, ClientCertRequest handler) { super.onReceivedClientCertRequest(view, handler); } @Override public void onDocumentLoadedInFrame(XWalkView view, long frameId) { super.onDocumentLoadedInFrame(view, frameId); } @Override public void onReceivedHttpAuthRequest(XWalkView view, XWalkHttpAuthHandler handler, String host, String realm) { super.onReceivedHttpAuthRequest(view, handler, host, realm); } @Override public void onReceivedLoadError(XWalkView view, int errorCode, String description, String failingUrl) { super.onReceivedLoadError(view, errorCode, description, failingUrl); } @Override public void onReceivedResponseHeaders(XWalkView view, XWalkWebResourceRequest request, XWalkWebResourceResponse response) { super.onReceivedResponseHeaders(view, request, response); } } ); mXWalkView.setUIClient(new XWalkUIClient(mXWalkView) { @Override public void onPageLoadStarted(XWalkView view, String url) { super.onPageLoadStarted(view, url); } @Override public boolean onJsAlert(XWalkView view, String url, String message, XWalkJavascriptResult result) { return super.onJsAlert(view, url, message, result); } @Override public void onScaleChanged(XWalkView view, float oldScale, float newScale) { super.onScaleChanged(view, oldScale, newScale); } @Override public void onPageLoadStopped(XWalkView view, String url, LoadStatus status) { super.onPageLoadStopped(view, url, status); } }); mXWalkView.loadUrl("https://h5vtest.cmbc.com.cn:7443/server/h5-7.4/"); } @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.waklk); mXWalkView = findViewById(R.id.xwalkView); } @Override public void onPointerCaptureChanged(boolean hasCapture) { } }
4,activity添加进AndroidManifest.xml,就可以正常使用XWalkView了