Webview不被视为移动浏览器

Ric*_*ick 1 android

在我的webview中,我将 通过Android浏览器将其视为移动网站http://www.nsopw.gov/Core/OffenderSearchCriteria.aspx.

但是在我的webview应用程序中,它被视为不是移动浏览器,因此没有被重定向到移动版本.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.buttons);
    wb = new WebView(this);
    wb.getSettings().setJavaScriptEnabled(true);
    wb.setWebViewClient(new HelloWebViewClient());
    wb.getSettings().setSupportZoom(true);
    wb.getSettings().setBuiltInZoomControls(true);
    wb.getSettings().setDomStorageEnabled(true);
    String[] loading = getResources().getStringArray(R.array.array_loading);

    Random r = new Random();
    int rN = r.nextInt(12 - 1) + 1;
    progressBar = ProgressDialog.show(Sex_Offenders.this, loading[rN],
            "Loading...");

     final String urlToLoad ="http://www.nsopw.gov/Core/OffenderSearchCriteria.aspx";
    //final String urlToLoad = "http://m.familywatchdog.us/m_v2/msa.asp?es=&l=0&w=0&brtp=html&rstp=xlarge&imgtp=jpg&imgw=310&imgh=320";

    wb.setWebViewClient(new HelloWebViewClient() {
        public void onPageFinished(WebView view, String url) {

            if (progressBar.isShowing()) {
                progressBar.dismiss();
            }
        }
    });

    Context context = getApplicationContext();
    if (Repeatables.isNetworkAvailable(context) == true) {
        wb.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
        wb.loadUrl(urlToLoad);
    } else {
        wb.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
        wb.loadUrl(urlToLoad);
        Repeatables.NoConnectionAlert(this);
    }
    setContentView(wb);
Run Code Online (Sandbox Code Playgroud)

Orl*_*mee 6

尝试自己强制使用用户代理字符串,因为看起来webview用户代理字符串不会将自己标识为移动浏览器.使用

webview.getSettings.setUserAgentString(...)
Run Code Online (Sandbox Code Playgroud)

您可以谷歌搜索我使用的useragent字符串

Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
Run Code Online (Sandbox Code Playgroud)

它与你在网站上提供的链接一起使用并加载了移动版本.

  • wb.getSettings().setUserAgentString("Mozilla/5.0(iPhone; U; CPU,如Mac OS X; en)AppleWebKit/420 +(KHTML,如Gecko)Version/3.0 Mobile/1A543a Safari/419.3"); (3认同)