tag:blogger.com,1999:blog-8219113377173546175.post5457736711378456798..comments2023-11-07T13:29:54.725+00:00Comments on GT's Blog: Calling JavaScript Function from Android and Handling ResultGThttp://www.blogger.com/profile/16923656636145211711noreply@blogger.comBlogger12125tag:blogger.com,1999:blog-8219113377173546175.post-2957740904766024052014-06-12T13:13:00.735+01:002014-06-12T13:13:00.735+01:00hello
Thank you for the post.
There is an alrea...hello <br /><br />Thank you for the post.<br /><br />There is an already impemented site, which i use to make an app in android using webview.<br />There is a button already which on the site works perfectly but does nothing on my app. <br />I can understand your code so here is my question:<br /><br />Do I need to make a new button in android to use the function of the existing one which is in the website? Like you did here:<br />a)Add a Button to Android UI and add onClickListener to it. We will call JavaScript's getValue() method on onClick event of this Button.<br />callBtn = (Button) findViewById(R.id.callBtn);<br />callBtn.setOnClickListener(new OnClickListener() {<br /> @Override<br /> public void onClick(View v) {<br /> //this calls javascript function<br /> webView.loadUrl("javascript:getValue()");<br /> }<br />});<br /><br /><br />or i can somehow detect the clicking of the button of the website in order to call the function?<br /><br />Thank youAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8219113377173546175.post-12100146160806918482013-11-28T07:57:40.295+00:002013-11-28T07:57:40.295+00:00hello,
Thank you for the post,
I want to ask one ...hello,<br /><br />Thank you for the post,<br />I want to ask one thing<br /><br />Can we use javascript methods and the java methods from the same html file, if yes then how????<br /><br />Thanks in advance.Anonymoushttps://www.blogger.com/profile/10561011915894201640noreply@blogger.comtag:blogger.com,1999:blog-8219113377173546175.post-43018755507646305472013-08-12T04:19:39.949+01:002013-08-12T04:19:39.949+01:00you can put your html file in asset directory and ...you can put your html file in asset directory and load as follows:<br /><br />//webView.loadUrl("file:///android_res/raw/testhtml.html");<br />webView.loadUrl("file:///android_asset/testhtml.html");<br /><br />for more detail : read the webview related articles given in : http://ganeshtiwaridotcomdotnp.blogspot.com/search/label/AndroidAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8219113377173546175.post-54210120830450276512013-07-31T16:49:06.183+01:002013-07-31T16:49:06.183+01:00Where have you loaded html file in your code? I co...Where have you loaded html file in your code? I could not get it done.Anonymoushttps://www.blogger.com/profile/18213409090191630887noreply@blogger.comtag:blogger.com,1999:blog-8219113377173546175.post-59319535799173144632013-04-21T04:21:32.805+01:002013-04-21T04:21:32.805+01:00According to Google documentation "Caution: I...According to Google documentation "Caution: If you've set your targetSdkVersion to 17 or higher, you must add the @JavascriptInterface annotation to any method that you want available to your JavaScript ".<br />Taht could solve your problem.<br /><br />Source : http://developer.android.com/guide/webapps/webview.htmlCédric Soubriéhttps://www.blogger.com/profile/11843324382480320967noreply@blogger.comtag:blogger.com,1999:blog-8219113377173546175.post-29059411714072502892013-02-01T09:24:06.943+00:002013-02-01T09:24:06.943+00:00that didn't work on android version 4.0.4 its ...that didn't work on android version 4.0.4 its fine on earlier versionAnonymoushttps://www.blogger.com/profile/08211162850716860320noreply@blogger.comtag:blogger.com,1999:blog-8219113377173546175.post-79785961292254933032011-12-06T05:08:18.246+00:002011-12-06T05:08:18.246+00:00As you said "How would I send what is inside ...As you said <b>"How would I send what is inside String tester of JavaScriptInterface class to the webView that is contained in my main class?"</b> <br />--> you want to call some functions on JavaScript of your webview with some parameter.<br /><br />For this see my earlier blog <a href="http://ganeshtiwaridotcomdotnp.blogspot.com/2011/09/android-javascriptinterface-tutorial.html" rel="nofollow">Calling JavaScript function from Android" </a>GThttps://www.blogger.com/profile/16923656636145211711noreply@blogger.comtag:blogger.com,1999:blog-8219113377173546175.post-29977075958710045242011-12-05T19:17:04.784+00:002011-12-05T19:17:04.784+00:00Thank you for the followup Ganesh. I should have h...Thank you for the followup Ganesh. I should have hovered over the Eclipse error and it states right there that webView.loadUrl() returns a void. <br /><br />I know you must be busy so when you have time if you could point me in the right direction on one more thing, it would be appreciated.<br /><br />How would I send what is inside String tester of JavaScriptInterface class to the webView that is contained in my main class?<br /><br />Thanks for you time and effort in informing people like me how to code.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8219113377173546175.post-47525931360702344972011-12-03T06:33:24.178+00:002011-12-03T06:33:24.178+00:00String tester = webView.loadUrl("javascript:g...String tester = webView.loadUrl("javascript:getValue()"); doesnot return the value from webpage. Instead, we can get the form value from the callback function. here receiveValueFromJs. You got that error because webView.loadUrl() returns void.<br /><br />You should do the following :<br />public void receiveValueFromJs(String str) {<br />//you get the value from webpage in variable str.<br />String tester = str;<br />}GThttps://www.blogger.com/profile/16923656636145211711noreply@blogger.comtag:blogger.com,1999:blog-8219113377173546175.post-2482639003013242412011-12-01T18:56:07.413+00:002011-12-01T18:56:07.413+00:00Hello - thank you for posting this up. It is helpi...Hello - thank you for posting this up. It is helping me with my current project at work. I'm a complete Java/JS newbie and got a question. <br /><br />If I changed the receiveValueFromJs(String str) to return the str, how would I be able to access value of str in webview.<br /><br />Example:<br />String tester = webView.loadUrl("javascript:getValue()");<br /><br />I get a "Type mismatch: cannot convert from void to String" error. Thanks in advance!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8219113377173546175.post-48973417585579885602011-11-28T10:49:36.875+00:002011-11-28T10:49:36.875+00:00Thank you for the comment. I corrected it.Thank you for the comment. I corrected it.GThttps://www.blogger.com/profile/16923656636145211711noreply@blogger.comtag:blogger.com,1999:blog-8219113377173546175.post-11275194131445877072011-11-21T20:53:08.996+00:002011-11-21T20:53:08.996+00:00Hello.
"Here 'Android' will be use...Hello. <br /><br />"Here 'Android' will be used later..." should be "Here 'MyAndroid' will be used later..."Anonymousnoreply@blogger.com