问题
Relating to this SO question,
I want to remove the notifications as well as the flicker that occurs when displaying TeX in a WebView in android.
I tried the AsyncTask method, to preload the page and then "download" it, before loading the data into the WebView but I'm stuck on an IllegalStateException: Target host must not be null, or set in parameters. This error is coming from the following code:
protected String doInBackground(String... url) {
String r = "";
try {
HttpClient hc = new DefaultHttpClient();
HttpGet get = new HttpGet(URLEncoder.encode(url[0], "UTF-8"));
// get.setHeader("host", "http://myapp");
HttpResponse hr = hc.execute(get);
...
}
The line commented out is what I had tried to fix this error, but never worked.
Now I'm thinking I can't get around this because the url[0]
that I'm loading is in the form: javascript:somescript(input)
executed from a JS file stored in my assets, and maybe HttpGet requires a web server?
How can I hide the notifications and finish the JavaScript before updating the WebView then?
回答1:
The HttpGet
class is for an HTTP request, so the URL must start with http://
.
If you are using MathJax as the TeX viewer, then refering to this Stack Overflow question, you could add messageStyle: "none"
to your MathJax configuration. This way can disable MathJax's loading notifications in any environments.
来源:https://stackoverflow.com/questions/17145969/android-webview-how-to-load-page-after-javascript-execution