Before getting into the technical details, let me first talk about a situation where this piece of functionality would be useful. Lets say (for arguments sake), that you have to write an Android application that requires advanced and very polished charts. What are you options? You can try to find a native Android implementation that meets the requirement, but I must admit, I have been there and done that, and couldn’t find any particularly good libraries. Yes there are some out there, but they didn’t have the polish I was looking for (please comment if you know of good ones).
For simplicity, I am going to abstract away the charts and data and replace them with a simple requirement, namely, have a WebView render the underlyingAndroid SDK version.
Note: For the purposes of this post, and because I like it, I am going to use Scala as the programming language. As always, you can find all the code on Github.
1 2 3 4 5 6 7 8
So far, so easy. Next, we need to create a simple Scala function in our
1 2 3
1 2 3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Lets create a file called
index.html and place it under
src/main/assets and add at least the following code to it:
1 2 3 4 5 6 7 8 9 10 11
As you can see here, we are invoking the Android (Scala) method called
sdkVersion() and appending the results of the call to a div using JQuery.