You can execute JavaScript without a WebView. You can use AndroidJSCore . Here is a brief example of how you can do this:
HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet("http://your_website_here/file.js"); HttpResponse response = client.execute(request); String js = EntityUtils.toString(response.getEntity()); JSContext context = new JSContext(); context.evaluateScript(js); context.evaluateScript("question.vote(0);");
However, this most likely will not work outside of WebView, because I suppose you not only rely on JavaScript, but also on AJAX, which is not part of pure JavaScript. This requires a browser implementation.
Is there a reason you are not using hidden WebView and just entering your code?
// Create a WebView and load a page that includes your JS file webView.evaluateJavascript("question.vote(0);", null);
source share