Javascript 来自服务的Android WebView(无活动)

Javascript 来自服务的Android WebView(无活动),javascript,android,webview,android-context,Javascript,Android,Webview,Android Context,我尝试通过服务通知运行WebView。WebView运行良好,但我没有得到警报和一些JavaScript函数 这就是我创建WebView的方式(没有什么特别之处): 这是test.html文件: <!DOCTYPE html> <html> <head> <script> function myFunction() { alert("Hello! I am an alert box!");

我尝试通过服务通知运行WebView。WebView运行良好,但我没有得到警报和一些JavaScript函数

这就是我创建WebView的方式(没有什么特别之处):

这是test.html文件:

<!DOCTYPE html>
<html>
<head>
    <script>
    function myFunction()
    {
        alert("Hello! I am an alert box!");

        console.log("clicked");
    }
    </script>
</head>
<body>

<input type="button" onclick="myFunction()" value="Show alert box" />
</body>
</html>
有机会解决这个问题吗

有机会解决这个问题吗


实现一个真正的
WebChromeClient
,一个。你的
setWebViewClient()
setWebChromeClient()
setOnClickListener()
setOnTouchListener()
都是无用的,我怀疑
setBuiltinzoomControl()
requestFocusFromTouch()
对你也没有任何好处。

我会试试看!谢谢你的快速回答@你能帮我解决我的问题吗?这个解决了吗?我已经重写了WebChromeClient,并通过启动一个以对话框为主题的活动设置了一个处理onJsAlert()的新的WebChromeClient,但我仍然得到了错误me@jampez77如果这样的话,这对你有什么好处?你确定这样行吗?
<!DOCTYPE html>
<html>
<head>
    <script>
    function myFunction()
    {
        alert("Hello! I am an alert box!");

        console.log("clicked");
    }
    </script>
</head>
<body>

<input type="button" onclick="myFunction()" value="Show alert box" />
</body>
</html>
"Cannot create a dialog, the WebView context is not an Activity"