admin管理员组文章数量:1287265
I need to make some UI part in javascript for android application for that I'm writing some code in javascript and load it in android web view. Now, I want to call java class from javascript.
Is it possible to call java class from javascript?
Thanks in Advance!
I need to make some UI part in javascript for android application for that I'm writing some code in javascript and load it in android web view. Now, I want to call java class from javascript.
Is it possible to call java class from javascript?
Thanks in Advance!
Share Improve this question edited Jul 7, 2011 at 5:38 Buhake Sindi 89.2k30 gold badges175 silver badges232 bronze badges asked Jul 7, 2011 at 5:31 milindmilind 9704 gold badges12 silver badges39 bronze badges 2- Why are you splitting the application that way? Why not just write it all,including UI, in Java? – Soren Commented Jul 7, 2011 at 5:34
- because i need to draw much plex UI in android you can see the following question at stackoverflow./q/6596294/562296 – milind Commented Jul 7, 2011 at 5:39
3 Answers
Reset to default 4It's possible, but I wouldn't do it for your given use case :) (the UI could be done with the Android framework)
You can add what they call "Javascript Interfaces", which are basically links from Javascript to Java code. First, define a class to bind containing the methods you which to call, and add it to your WebView :
class HelloInterface
{
public void test(String name)
{
Log.i(TAG, "Hello " + name);
}
}
webview.addJavascriptInterface(new HelloInterface(), "HELLO");
Then, from your javascript code, you can just call
window.HELLO.test("Webview");
Refer the following urls,
http://www.rgagnon./javadetails/java-0170.html
Post #6 of-> http://ubuntuforums/showthread.php?t=565819
Hope this helps..
its actually reall easy (and cool) use:
webView.addJavascriptInterface(js, "pageObject");
js is a java object made in you activty (or somewhere where you init the webview), pageObject is the namespace identifier (variable) you can use with javaScript on your webpage.
本文标签: is it posible to call java class from javascriptStack Overflow
版权声明:本文标题:is it posible to call java class from javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741230130a2361967.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论