5
我想用Cordova構建自定義WebView。爲此,我想覆蓋setWebChromeClient和setWebViewClient方法。但爲此,我需要一個SystemWebViewClient,它需要一個SystemWebViewEngine,目前我似乎無法得到它。我的繼承人的主要活動在Android中使用Cordova 5.0構建自定義WebView
public class MyActivity extends CordovaActivity implements CordovaInterface {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
int threadSize = getResources().getInteger(R.integer.WIPThreadPoolSize);
// Initiate Thread pool
threadPool = new ThreadPoolExecutor(threadSize, threadSize, 10, TimeUnit.SECONDS, this.priorityQueue);
initApplicationInformationManager();
// initialize global variables
GlobalApplicationVariables.initValues(this);
isActivityReady = false;
isActivityReady = false;
setContentView(R.layout.main_layout);
super.init();
}
protected CordovaWebView makeWebView() {
SystemWebView webView = (SystemWebView) findViewById(R.id.customWebView);
SystemWebViewEngine engine = new SystemWebViewEngine(webView);
return new CordovaWebViewImpl(engine);
}
protected void createViews() {
appView.getView().requestFocusFromTouch();
}
}
而且我的自定義網頁流量:
@SuppressLint("SetJavaScriptEnabled")
public class CustomWebView extends SystemWebView {
private DebugServiceClient dbgClient;
public CustomWebView(Context context) {
super(context);
this.configureView(context);
}
public CustomWebView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
this.configureView(context);
}
/**
* Configure the web view.
*
* @param context
* Context web view is running in.
*/
private void configureView(Context context) {
//Make the WebView visible and hide its scroll bars
setVisibility(View.VISIBLE);
setVerticalScrollBarEnabled(false);
setHorizontalScrollBarEnabled(false);
setOverScrollMode(OVER_SCROLL_NEVER);
WebSettings webSettings = getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setSupportZoom(false);
webSettings.setAppCacheEnabled(false);
webSettings.setDomStorageEnabled(true);
final MyActivity myActivity = (MyActivity) context;
setWebChromeClient(new SystemWebChromeClient(new SystemWebViewEngine(this)) {
public void onShowCustomView(View view, CustomViewCallback callback) {
/*Custom code*/
}
public void onHideCustomView() {
/*Custom code*/
}
});
setWebViewClient(new SystemWebViewClient(new SystemWebViewEngine(this)) {
public boolean shouldOverrideUrlLoading(WebView webview, String url) {
/*Custom code*/
}
public void onReceivedError(WebView view, int errorCod, String description, String failingUrl) {
Log.e("Webview Error", errorCod + " - " + description + failingUrl);
}
});
}
}
真的不能得到一個引擎,這樣的方法可以被覆蓋,所以我創建了一個在運行,但是這會產生一些錯誤。此外,我似乎無法訪問科爾多瓦插件管理器,因此我無法添加插件到web視圖。哪種做法最好?
是你得到什麼錯誤? – JSON