WebView打开网站的静态版本(WebView opens static version of website)

编程入门 行业动态 更新时间:2024-10-25 22:26:21
WebView打开网站的静态版本(WebView opens static version of website) import android.app.Activity; import android.os.Bundle; import android.webkit.WebView; import android.webkit.WebViewClient; public class MainActivity extends Activity { private WebView mWebView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mWebView = (WebView) findViewById(R.id.web_view); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.setWebViewClient(new CustomWebViewClient()); mWebView.loadUrl("http://groupedirectouest.com"); } } class CustomWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }

当我使用ua(userAgent)字符串时,webview会显示桌面版本的网站。 这是我用过的字符串:

mWebView.getSettings().setUserAgentString("AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30");

这里是我试图在我的网站打开的网站

http://groupedirectouest.com/

它适用于Chrome而不是webview。

import android.app.Activity; import android.os.Bundle; import android.webkit.WebView; import android.webkit.WebViewClient; public class MainActivity extends Activity { private WebView mWebView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mWebView = (WebView) findViewById(R.id.web_view); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.setWebViewClient(new CustomWebViewClient()); mWebView.loadUrl("http://groupedirectouest.com"); } } class CustomWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }

when I use ua (userAgent) string, webview shows desktop version of website. here is the ua string i have used :

mWebView.getSettings().setUserAgentString("AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30");

here is the website that i am trying to open in my

http://groupedirectouest.com/

it works fine with chrome but webview.

最满意答案

现在有为您定制的铬标签!

如果您在应用程序内托管自己的内容,WebView是一个很好的解决方案。 如果您的应用引导用户访问您网域之外的网址,现在建议您使用Chrome自定义标签获得各种优惠。 按照下面的链接:

https://developer.chrome.com/multidevice/android/customtabs

Now there are custom chrome tabs for you!

The WebView is good solution if you are hosting your own content inside your app. If your app directs people to URLs outside your domain,it is now recommended that you use Chrome custom tabs for various benefits.Follow the link below:

https://developer.chrome.com/multidevice/android/customtabs

更多推荐

本文发布于:2023-08-07 04:47:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1460823.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:静态   版本   网站   WebView   website

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!