我正在尝试在android设备中的android webview中仅启用网站的桌面模式。但是它仅在移动视图中呈现。有什么方法可以强制视图仅在桌面模式下使用?
下面是我的Android网络视图代码
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.activity_home);
wb=(WebView)findViewById(R.id.webView1);
CookieManager.getInstance().setAcceptCookie(true);
wb.getSettings().setLoadWithOverviewMode(true);
wb.getSettings().setUseWideViewPort(true);
wb.getSettings().setJavaScriptEnabled(true);
wb.getSettings().setAllowFileAccess(true);
wb.getSettings().setAllowContentAccess(true);
wb.setScrollbarFadingEnabled(false);
WebSettings settings = wb.getSettings();
settings.setDomStorageEnabled(true);
settings.setLoadWithOverviewMode(true);
settings.setUseWideViewPort(true);
wb.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedSslError(WebView v, SslErrorHandler handler, SslError er){
handler.proceed();
}
/*@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url != null && (url.startsWith("http://") || url.startsWith("https://"))) {
view.getContext().startActivity(
new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return true;
} else {
return false;
}
}*/
});
wb.loadUrl("https://cppt01.chartercom.com/pathtrak/direct/sa?node=30AA1E");
wb.setVisibility(View.VISIBLE);
}
答案 0 :(得分:0)
尝试一下:
* private static final String desktop_mode = "Mozilla/5.0 (X11; Linux x86_64)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36";
* private static final String mobile_mode = "Mozilla/5.0 (Linux; U; Android 4.4; en-
us; Nexus 4 Build/JOP24G) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile
Safari/534.30";
//Choose Mobile/Desktop mode.
WebSettings settings = mWebView.getSettings();
settings.setUserAgentString(desktop_mode );