Android Sent Text To JavaScript

While developing Android application, sometimes we need to use webview and want our android (java code) communicate with html in webview. We can use javascript to communicate between java to html and vice versa. Dont forget to setting javascript enabled in our webview to true.

Please check code below to check how Android sent text to javascript :

Create file index.html code in assets directory. This is the contents from this html Android sent text to javascript file

Dont forget to create javascript file with name myscript.js and save to assets directory. This javascript is the important part, becuase used to communicate between java android and javascript (webview).

Please check below image for output Android sent text to javascript code :

Image. Sent Text From Android To JavaScript
Sent Text From Android To JavaScript
Image. Sent Text From JavaScript Android
Sent Text From JavaScript Android

This is a simple tutorial how Android sent text to javascript and how to javascript or webview sent text to Android. I hope this tutorial can help you solve your problem. You can download the compete code Android sent text to javascript in here.

Source : http://www.cuelogic.com/blog/simple-android-java-javascript-bridge/

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.