Welcome!

Search Authors: Jnan Dash, Shelly Palmer, Kevin Benedict, Alex Forbes, Bob Gourley

Blog Feed Post

SureFox Javascript APIs

SureFox for Android now comes with built-in set of Javascript APIs. Use them in a customized SureFox toolbar or embed in your web application to perform variety of actions such as navigating through pages or to launch an app directly from SureFox.

The APIs are written as window.surefox.<API_Name>

Following is a comprehensive list of SureFox APIs:

  • load(URL): Loads the URL in the active screen of SureFox. URL is passed as a parameter to the API
window.surefox.load('http://www.google.com');
  •  openInNewTab(URL): Loads the URL in a new tab of SureFox. URL is passed as a parameter to the API
window.surefox.openInNewTab('http://www.google.com');
  • back(): Navigate to the previous page in SureFox
window.surefox.back();
  • forward(): Navigate to the next page in SureFox
window.surefox.forward();
  • home(): Loads SureFox home page
window.surefox.home();
  • refresh(): Refreshes current web page
window.surefox.refresh();
  • stop(): Stops any ongoing loading activity in SureFox
window.surefox.stop();
  • launch(packagename): Launches the application from SureFox. Only the package name of the application needs to be passed as a parameter to the API.
window.surefox.launch('com.android.contacts');
  • launch(action,category,packagename,classname): Use this to launch a particular activity of an application from SureFox. The action, category, package name and class name of the application need to be passed as parameters to the API.
window.surefox.launch('android.intent.action.MAIN', 'android.intent.category.LAUNCHER', 'com.android.contacts', 'com.android.contacts.activities.PeopleActivity');

You can also use SureFox APIs to get and display battery status and perform actions based on the battery level. Following are the list of SureFox battery APIs:

  • battery().level(): Returns the current battery level
window.surefox.battery().level()
  • battery().charging(): Returns 'true' if battery is charging else returns a 'false'
window.surefox.battery().charging()
  • battery().addEventListener("levelchange", "<user-defined-function>"): Used to add an event listener for battery level which can be used to call any function of your choice
window.surefox.battery().addEventListener("levelchange", "setLevel");
  • battery().addEventListener("chargingchange", "<user-defined-function>"):
window.surefox.battery().addEventListener("chargingchange", "setStatus");

 

Sample HTML page for displaying use of SureFox APIs:

SureFox Javascript API Demo page

SureFox Javascript API Demo page

HTML Code for demo page:

<html>
 <head>
 <title>SureFox Javascript APIs</title>
 <script type="text/javascript">
 function setLevel(value) {
 document.querySelector('#level').textContent = "Battery Level = " + value+"%";
 }
 function setStatus(value) {
 document.querySelector('#status').textContent = "Charging: " + window.surefox.battery().charging();
 }
 function init() {
 setLevel(window.surefox.battery().level() * 100);
 setStatus(window.surefox.battery().charging());
 window.surefox.battery().addEventListener("levelchange", "setLevel");
 window.surefox.battery().addEventListener("chargingchange", "setStatus");
 }
 </script>
 </head>

 <body onload="javascript:init()">

 <div id="container" style="background-color: #cccccc;">
 <div style="float:right;">
 Real Time Battery Status:<div id="status">(charging state unknown)</div>
 <div id="level">(battery level unknown)</div>
 </div>
 <span onclick="window.surefox.home();"><button>Home</button></span>
 <span onclick="window.surefox.back();"><button>Back</button></span>
 <span onclick="window.surefox.forward();"><button>Forward</button></span>
 <span onclick="window.surefox.refresh();"><button>Refresh</button></span>
 <span onclick="window.surefox.stop();"><button>Stop</button></span>
 <span onclick="window.surefox.launch('com.android.calendar');"><button>Calendar</button></span>
 <span onclick="window.surefox.launch('android.intent.action.MAIN', 'android.intent.category.LAUNCHER', 'com.android.vending', 'com.android.vending.AssetBrowserActivity');"><button>Google Play</button></span>
 <br />
 <b><span onclick="window.surefox.load('http://www.42gears.com');">Click to visit 42Gears</span>
 <br />
 <span onclick="window.surefox.openInNewTab('http://www.google.com');">Click to launch Google(Open in new tab)</span></b>
</div>
</body>
 </html>

To know more about SureFox, click here

To learn more on how to secure and manage Android, iOS and Windows Mobile/CE devices efficiently, visit us at www.42gears.com

Read the original blog entry...

More Stories By Onkar Singh

The author is the founder of 42Gears, developer of affordable Mobile Device Management tools.