Hello,

I need to evaluate javascript from within a Service.

In an Activity I used to do that with WebView. However after
constructing a WebView in the service (passing its context to the
WebView) and calling loadUrl (with the url of the page containing the
javascript that needs to be evaluated) nothing seems to happen. The
page never gets loaded.

I assume that the problem is that Webview does not support Service
context and requires an Activity context.. is there any solution to
that? Your help/ideas are greatly appreciated!!

My code within the service looks like this:

web = new WebView(context); //Service context
web.getSettings().setJavaScriptEnabled(true);
web.addJavascriptInterface(new JavaScriptInterface(), "HTMLOUT");
web.setWebViewClient(new WebViewClient() {
    @Override
    public void onPageFinished(WebView view, String url)
    {
       //The page never gets loaded, so this code is never reached in
Servicce :(((((
        web.loadUrl("javascript:window.HTMLOUT.showHTML("+javacode
+");");
    }
});
web.loadUrl(url);

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to