Week 2.5 – androidJsBridge

Its been almost two and a half weeks since the GSoC coding period started and it has been nothing less than interesting. Finally, after quite a few hours of coding I’ve been able to successfully integrate the Posting-Applications, PlainPost and Zerobin, with the Privly Android Application.

The Posting applications being in Javascript created a really interesting problem of integration with the Native Android Code. Something I had never really worked with before.  The solution was however pretty simple. A Js interface is added to the WebView which enables the Js to talk to Java and then depending on the user selection, the Js code for either of the Posting Applications is loaded in the WebView.

WebView w = (WebView)findViewById(R.id.webview_1);
w.addJavascriptInterface(new JsObject(this), "androidJsBridge");

The JsObject Class defines the functions that are accessible to Js.


public class JsObject{

    Context c;

    JsObject(Context callingContext){
        c = callingContext;

    public String getDeviceVersion(){
        String deviceVersion= Build.VERSION.RELEASE;
        Log.d("androidJSBridge Version Request",deviceVersion);
        return deviceVersion;

And the Js Code of the Posting-Applications can access these functions by using the androidJsBridge.
For example –

var android_version = androidJsBridge.getDeviceVersion();

I also pushed some Android specific Js code to the Posting-Applications branch and now, the Android Application is now able to generate PlainPost and ZeroBin Links and allows the user to share the new Privly Urls.

Latest Code for the Android App — https://github.com/vshivam/privly-android

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s