I am trying to execute a JS function in my Android app. The function is in a .js file on a website.
I am not using webview, I want to execute JS function because it sends my request.
The console in my browser just has to ask me questions. Vote (0); , how can I do this in my app?
You can execute JavaScript without webwives. you can use . This is a quick example of how you can do it:
HTTP client 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 References = New JSContext (); Context.evaluateScript (js); Context.evaluateScript ("question.vote (0);"); However, this will most likely not work out of a WebView because I think that you are not just relying on Javascript, but AJAX, which is not part of pure JavaScript. This requires a browser implementation. Is there any reason why you do not use hidden WebView and just inject your code?
// Create a webview and load a page in which your JS file contains webView.evaluateJavascript ("question.vote (0);", null);
No comments:
Post a Comment