More and more I see entire products built on this ability which is pretty simple really .
How can we connect a responsive and dynamic UI such as Html5 that is able to migrate easily between devices with the Java ability of controlling the device under Android OS ?
The idea is to :
- Set the promise and enabling usage of javascript interface in Java
- Create the corresponding implementation for the javascript interface in Java
- Call the Java class and functionality from javascript – letting you control the device with the whole power of Java drivers from html5 – JQuery UI .
How to recipe :
- in App.java :
private DefMemoryReleaser dmr ;
super.appView.getSettings().setJavaScriptEnabled(true);
dmr = new DefMemoryReleaser(this, appView);
appView.addJavascriptInterface(dmr, “JavaDefMemoryReleaser”);
- buildjava corresponding class DefMemoryReleaser
package com.EggedDefinition;
import org.apache.cordova.DroidGap;
import android.webkit.WebView;
public class DefMemoryReleaser {
private WebView mAppView;
private DroidGap mGap;
public DefMemoryReleaser(DroidGap gap, WebView view)
{
mAppView = view;
mGap = gap;
}
public void freeMemory(){
System.runFinalization();
Runtime.getRuntime().gc();
System.gc();
}
}
- in javascript :
if (typeof (window.JavaDefMemoryReleaser) != ‘undefined’)
window.JavaDefMemoryReleaser.freeMemory();
Now you are ready and set to build and sell security products for Android – Godspeed ! 🙂