How do I pass return values from a javascript function to android?

I just got your problem Have a JS function like this function androidResponse() { window.cpjs. SendToAndroid("I am being sent to Android. "); } Set up Android (Java) Have a final class like this final class IJavascriptHandler { IJavascriptHandler() { } public void sendToAndroid(String text) { // this is called from JS with passed value Toast t = Toast.

MakeText(getApplicationContext(), text, 2000); t.show(); } } Then on your WebView load have webView. AddJavascriptInterface(new IJavascriptHandler(), "cpjs") Call JS function webView. LoadUrl("javascript:androidResponse();void(0)") UPDATED Also I had a very bad time experiencing problems while passing hundreds of lines of string to JS from Java and I have subsequent post on StackOverflow with no good answers but finally resolved it knowing problme was of special characters inside string so take of special characters when you use string passing to and fro Passing Data From Javascript To Android WebView HTML String Inside Nested String HTML TextArea Characters Limit Inside Android WebView.

I just got your problem. Have a JS function like this. Function androidResponse() { window.cpjs.

SendToAndroid("I am being sent to Android. "); } Set up Android (Java). Have a final class like this final class IJavascriptHandler { IJavascriptHandler() { } public void sendToAndroid(String text) { // this is called from JS with passed value Toast t = Toast.

MakeText(getApplicationContext(), text, 2000); t.show(); } } Then on your WebView load have. WebView. AddJavascriptInterface(new IJavascriptHandler(), "cpjs"); Call JS function webView.

LoadUrl("javascript:androidResponse();void(0)"); UPDATED Also I had a very bad time experiencing problems while passing hundreds of lines of string to JS from Java and I have subsequent post on StackOverflow with no good answers but finally resolved it knowing problme was of special characters inside string so take of special characters when you use string passing to and fro. Passing Data From Javascript To Android WebView HTML String Inside Nested String HTML TextArea Characters Limit Inside Android WebView.

Edited as I understand the problem now. – Umair Ashraf Mar 10 at 19:20 Thanks for your response. I have been doing a similar thing here.

I have found that the calls from java to javascript are asynchronous, but the ones backwards are synchronous. Is that right? Also, have you noticed any message loss from javascript to java in your experiment?

– Weijia Li Mar 10 at 19:52 This is obvious the first one is asynchronous and the other one is synchronous but I have not read the documentation. My job was more toward sending huge HTML data from Java to JS and I did find loss of data due to special characters in the long string of HTML and I also find that we can't just pass huge HTML string using webView. LoadUrl("..."); so I got a workaround for this.

– Umair Ashraf Mar 11 at 5:36 1 What characters provoke problems? How huge is ”huge”? – Robert Siemer Jul 23 at 21:58.

Have a JS function like this. Set up Android (Java). Then on your WebView load have.

Also I had a very bad time experiencing problems while passing hundreds of lines of string to JS from Java and I have subsequent post on StackOverflow with no good answers but finally resolved it knowing problme was of special characters inside string so take of special characters when you use string passing to and fro.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions