Tips and Tricks in a world of Mix

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 :

  1. Set the promise and enabling usage of javascript interface in Java
  2. Create the corresponding implementation for the javascript interface in Java 
  3. 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 !  :)

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

Tag Cloud

%d bloggers like this: