Util JavaScript Functions

You can find the JavaScript test page at https://www.android-kiosk.com/jstest.htm Just set this as the Kiosk URL on your device to test the functions.

Show Android Toast Message
Shows your message in a toast.

<script>
function showAndroidToast(toast) {
Android.showToast(toast);
}
</script>
<a href="javascript:showAndroidToast('I am a toast message!')">Display message in Toast</a>


Show Android Snackbar Message
Shows your message in a snackbar, requires version 2.0.40 or higher.

<script>
//SHOWS MESSAGE IN SNACKBAR
function showSnackbar(message) {
Android.showSnackbar(message);
}
</script>
<a href="javascript:showSnackbar('I am a snackbar message!')">Display message in Snackbar</a>


Play Default Notification Sound
Plays default notification sound.

<script>
//PLAY DEFAULT NOTIFICATION SOUND
function playNotificationSound(milliseconds) {
Android.playNotificationSound();
}
</script>
<a href="javascript:playNotificationSound();">Play Notification Sound</a>


Show Keyboard
Shows keyboard (please note on some devices the keyboard will be toggled, so if already shown it will be hidden).

<script>
//SHOW KEYBOARD
function showKeyboard() {
Android.showKeyboard();
}
</script>
<a href="javascript:showKeyboard();">Show Keyboard</a>


Hide Keyboard
Hides keyboard.

<script>
//HIDE KEYBOARD
function hideKeyboard() {
Android.hideKeyboard();
}
</script>
<a href="javascript:hideKeyboard();">Hide Keyboard</a>


Create Log Entry
Creates log entry in default kioskbrowseractivity.log

<script>
function createLogEntry(url) {
Android.createLogEntry(url);
}
</script>
<a href="javascript:createLogEntry('http://www.google.com');">Create Log Entry</a>


Read Text File
Returns string of text from file. Requires v2.6.2 or higher.

<script>
function readTextFile(filepath) {
console.log(Android.readTextFile(filepath));
}
</script>
<a href="javascript:readTextFile('/storage/emulated/0/test.txt');">Read Text File</a>


Hide/Show System Bar
Hides or shows system bar, only available on rooted devices. Requires v2.6.0 or higher.

<script>
//HIDE SYSTEM BAR (ROOT ONLY)
function hideSystemBarRoot(hide) {
Android.hideSystemBarRoot(hide);
}
</script>
<a href="javascript:hideSystemBarRoot(true);">Hide System Bar (root only) v2.6.0 or higher</a>
<a href="javascript:hideSystemBarRoot(false);">Show System Bar (root only) v2.6.0 or higher</a>


Activate/Deactivate Licence
Activates or deactivates PRO licence. Requires v2.6.0 (build 194) or higher.

<script>
//ACTIVATE LICENCE KEY
function activateLicence(licencekey, email) {
return Android.activateLicence(licencekey, email);
}
//DEACTIVATE LICENCE KEY
function deactivateLicence() {
return Android.deactivateLicence();
}
</script>
<a href="javascript:activateLicence('23QU-3737-A22E-4KJ9-91AE','testing@android-kiosk.com');">Activate Licence Key</a><br/>
<a href="javascript:deactivateLicence();">Deactivate Licence Key</a><br/>


Remote Management device action "Execute kbRemoteFunction() on device"
Example kbRemoteFunction. Requires v2.6.2 or higher.

<script>
function kbRemoteFunction() {
showSnackbar('Remote function executed!');
}
</script>


Shutdown device
Shuts down device (some devices display timer), does not work on all devices. Requires v2.6.6 or higher.

<script>
function lenovoQualcommShutdown() {
Android.lenovoQualcommShutdown();
}

function mediatekShutdown() {
Android.mediatekShutdown();
}

</script>
<a href="javascript:lenovoQualcommShutdown();">Shutdown Lenovo device (Qualcomm based Devices)</a>
<a href="javascript:mediatekShutdown();">Shutdown Mediatek device</a>


Get Directory Contents
Gets contents of specified directory, returns array of file (path & name). Requires v2.6.6 or higher.
<script>
var includesubfolders = true;
var result = Android.getDirectoryContents('%LOCALCONTENT%/pdfs', includesubfolders);
var result2 = Android.getDirectoryContents('/sdcard/localcontent/pdfs', includesubfolders);
var array = JSON.parse(result);
for (var i in array) {
var file = array[i];
console.log(file.name);
console.log(file.path);
console.log(file.relativepath);
}
</script>
Was this article helpful?
Thank you!