我需要在我的應用程序中打開網站,但它只加載到Android 4.4和更新的設備上。但我需要打開網站並使用較舊版本的設備。我試圖連接HTML5,但它似乎在某個地方犯了一個錯誤。
該網站包含HTML5和JS代碼。這裏是我的Activiti網站不希望加載在API <19(KitKat)
WebView web;
ProgressBar progressBar;
@SuppressLint("SetJavaScriptEnabled")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.web);
setView();
initToolbar();
web = (WebView) findViewById(R.id.webview);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
progressBar.setMax(100);
progressBar.setProgress(0);
web.setWebChromeClient(new myWebChromeClient());
web.setWebViewClient(new myWebClient());
web.getSettings().setJavaScriptEnabled(true);
web.getSettings().setDisplayZoomControls(true);
web.getSettings().setLoadWithOverviewMode(true);
web.getSettings().setUseWideViewPort(true);
web.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
web.getSettings().setPluginState(WebSettings.PluginState.ON);
enableHTML5AppCache();
web.loadUrl("https://mobile.akbars.ru");
}
private void enableHTML5AppCache() {
web.getSettings().setDomStorageEnabled(true);
// Set cache size to 8 mb by default. should be more than enough
web.getSettings().setAppCacheMaxSize(1024*1024*8);
web.getSettings().setAppCachePath("/data/data/"+ getPackageName() +"/cache");
web.getSettings().setAllowFileAccess(true);
web.getSettings().setAppCacheEnabled(true);
web.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
}
public void setValue(int progress) {
this.progressBar.setProgress(progress);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Log.d("ACTIVTTY", "change rotation");
}
public class myWebClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
progressBar.setVisibility(View.VISIBLE);
view.loadUrl(url);
return true;
}
/*@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// TODO Auto-generated method stub
super.onPageStarted(view, url, favicon);
progressBar.setVisibility(View.VISIBLE);
}*/
/*@Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
super.onPageFinished(view, url);
progressBar.setVisibility(View.GONE);
}*/
}
public class myWebChromeClient extends WebChromeClient {
@Override
public void onProgressChanged(WebView view, int newProgress) {
WebViewActivity.this.setValue(newProgress);
super.onProgressChanged(view, newProgress);
}
}
// To handle "Back" key press event for WebView to go back to previous screen.
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if ((keyCode == KeyEvent.KEYCODE_BACK) && web.canGoBack()) {
web.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
的一個例子。在Android 5.0及更高版本這個網站可以在默認瀏覽器,但在Android的早期版本只在谷歌瀏覽器打開打開。
有沒有辦法在我的webview中繼承Google Chrome?
或其他一些想法來打開此網站?