无法在Android WebView中加载我的URL,但在Android浏览器中加载URL

时间:2019-06-10 11:46:14

标签: android android-webview

我正在尝试从android webview加载我的云URL之一,但它始终返回HTTP状态401。如果我从Chrome移动浏览器尝试过,其工作将达到预期。即使在iOS WebView中,它也可以正常工作。

这是我的代码,请有人帮助我。

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_xoi);

    base_url = "https://vision.xoeye.io/partners/abcd/share?";
String params = "shareId=12345678910111213141516" +
        "&serviceTicket=123-123&" +
        "customer=Manikanta&" +
        "location=3201 S. State St. Chicago IL 60616";

    webView = findViewById(R.id.webView);

    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
    webView.getSettings().setDomStorageEnabled(true);
    webView.clearHistory();
    webView.clearCache(false);
    webView.getSettings().setSupportZoom(true);
    webView.getSettings().setUseWideViewPort(true);
    webView.getSettings().setLoadWithOverviewMode(true);
    webView.clearFormData();
    webView.getSettings().setJavaScriptEnabled(true);

    webView.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
            return false;
        }
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
        }
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
        }
    });


    webView.loadUrl(base_url);
}

1 个答案:

答案 0 :(得分:0)

  

尝试

protected void onCreate(Bundle savedInstanceState) 
{
     super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_xoi);

     base_url = base_url+params;
     webView = findViewById(R.id.webView);

     WebSettings webSettings=webView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webView.getSettings().setLoadWithOverviewMode(true);
        webView.getSettings().setUseWideViewPort(true);
        webView.getSettings().setBuiltInZoomControls(true);
        webView.getSettings().setPluginState(WebSettings.PluginState.ON);
        webView.setWebViewClient(new HelloWebViewClient());
        //add here additional setting which you want
        webView.loadUrl(base_url);
}

private class HelloWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        return false;
    }

    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        super.onPageStarted(view, url, favicon);
    }


    @Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);
    }
}

希望这会对您有所帮助。