JS: Util
![](https://storage.crisp.chat/users/helpdesk/website/f891df320cad6800/browserlauncher_106ztwe.png)
Please note most functions apply to both Kiosk Browser and Launcher but some are specific the individual product.
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 Kiosk Browser 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>
Listen to Key Events
Listens to key presses and returns data via listener. Requires v2.6.2 or higher.
<script>
//REGISTER KEY EVENT LISTENER
function registerKeyEventListener(listener) {
Android.registerKeyEventListener(listener);
}
function myKeyEventListener(keyCode, displayLabel, number) {
console.log("keyCode: " + keyCode);
console.log("displayLabel: " + displayLabel);
console.log("number: " +number);
}
</script>
<a href="registerKeyEventListener("myKeyEventListener");">Register Listener</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>
Create Native Android Notification
Creates a native Android notification which will be displayed on paired devices such as a smart watches. Please note, when specifying the id, use 1 or higher, if the same ID is used it will replace the existing notification rather than creating a new one. Requires v2.7.3 or higher.
<script>
function createNativeNotification(id, title, message) {
Android.createNativeNotification(id, title, message);
}
</script>
<a href="javascript:Android.createNativeNotification(99, 'title','This is my message');">Create native android notification</a>
Get/Set Automatic Config Url
Gets and sets automatic config url. Set download=true to download the config after setting the url. Requires v2.7.8 or higher.
<script>
function setAutomaticConfigUrl(url, download) {
Android.setAutomaticConfigUrl(url, download);
}
function getAutomaticConfigUrl() {
return Android.getAutomaticConfigUrl();
}
</script>
<a href="javascript:setAutomaticConfigUrl('https://www.android-kiosk.com/kbconfigtest.json', true);">Set automatic config url</a>
<a href="javascript:showAndroidToast(getAutomaticConfigUrl());">Get automatic config url</a>
Updated on: 03/03/2021
Thank you!