I’ve been looking about for a proper explanation about javascript’s relationship with the android WebView. Can anyone tell me: if I an HTML page online and all the required javascript files to make what I need work on that HTML page, can I port it to android.
For example could I move the javascript files onto the android app local folder ( if so: which folder? ) and call a function from in the app. Then could I get the result of the javascript function from one of those files?
If anyone has any tutorials or resources related to this could you point me in the right direction?
When you have a WebView you can set a Webchormeclient or a Webviewclient, the webchromeclient will be similar to your chrome desktop browser. The other option is to use a Webviewclient this webview client can be configurated as you wish, you can add an “interface” to call Javascript functions from your java code, or java functions from your Javascript code.
The interface is a class and can be something like this:
final class JavaScriptInterface {
The webview has a method to “attach” this class to the Javascript:
Once you have add the JavascriptInterface, you can call the method myalert(“hi”) from the Javascript code, to do so, you will have to do something like:
if you want to call a Javascript from the Java code you can do something like this:
To sum up, the webchromeclient is easier to use but the webviewclient allows you more configuration. Before, maybe you want to read about phonegap which is a framework to devlop Webapps x-platform.
Hope you that this fast explanation helps you a little.
PS: With the second option you can store all that you need in the sdcard.