How to Hide Android WebView Notifications?

為{幸葍}努か 提交于 2019-12-24 07:46:57

问题


I am using 8 - 10 different WebViews in one layout and loading different content in each WebView.

While loading Webview shows different messages like "Loading.." "Processing.." etc.

Is there any way to hide these notifications?


回答1:


Try to use HttpClient to get the webpage's html code and then use WebView.loadData to load the entire page into WebView.

private class exampleHttpTask extends AsyncTask<Integer, Integer, String> {
    public String convertStreamToString(InputStream is, String charset) throws IOException {
        if (is != null) {
            Writer writer = new StringWriter();
            char[] buffer = new char[1024];
            try {
                Reader reader = new BufferedReader(new InputStreamReader(is, charset));
                int n;
                while ((n = reader.read(buffer)) != -1) {
                    writer.write(buffer, 0, n);
                }
            } finally {
                is.close();
            }
            return writer.toString();
        } else {
            return "";
        }
    }

    protected String doInBackground(Integer... params) {
        String r = "";
        try {
            HttpClient hc = new DefaultHttpClient();
            HttpGet get = new HttpGet("http://google.com"); // replace with the url
            HttpResponse hr = hc.execute(get);

            if(hr.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                InputStream is = hr.getEntity().getContent();
                r = convertStreamToString(is, "UTF-8");
            } else {
                r = "Error";
            }
        } catch(Exception e){
            e.printStackTrace();
        }
        return null;
    }

    protected void onPostExecute(String result) {
        WebView wv = (WebView) findViewById(R.id.web_view); // replace web_view with the webView id
        wv.loadData(result, "text/html", "utf-8");
    }

    protected void onPreExecute() {
    }

}

Then call new exampleHttpTask().exec() to load the webpage.



来源:https://stackoverflow.com/questions/13915354/how-to-hide-android-webview-notifications

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!