Trigger JavaScript Scripts Using Android Legacy Script

Publish Date: 23-Jun-2025 Last Modified Date: 26-Aug-2025 SOTI MobiControl
202 0

Summary

This article describes how to trigger Android JavaScript Scripts by using Android Legacy script.

Related SOTI ONE Platform Products

SOTI MobiControl

Related Device OS

Android Classic;Android Enterprise

Process Description

Note: This is a three-part process to trigger Android JavaScript scripts by using an Android legacy script.

Part 1: Create a Package 

1. From the SOTI MobiControl the web console, select Packages from the main menu. The Packages view opens.

2. Select the Add a Package button at top-right corner and select Create.

3. Select Android.
4. Fill in or select an option for the following fields, then select Next.
5. In the Scripts tab, select (+) to add a script, and select Post-Install for the Execution Step:
1.5. device inactivity import package-2 

6. Copy and paste the folowing example JavaScript (or other available JavaScript scripts) into the Script Editor and select Save.

#!/usr/bin/env js
	mobicontrol.message.createInfoDialog('This JavaScript Script generated from Android Legacy Script').show(); //log message on device screen 

7. Select Next and Publish to complete creating a package.

Part 2: Distribute the Package to Android Devices

1. In the SOTI MobiControl web console, navigate to the File Sync section and create a new file sync policy. Select Next to continue.2. Choose Download from Server as the file sync type. In the File Settings section, complete the following fields:

  • Server File/Folder Name: Specify the path to your JSON file on the server, for example., %ROOT%/MobiControl.
  • Device File/Folder Name: Specify the destination path on the Android device, e.g., %sdcard%/Download/Triggering JavaScript Script from Android Legacy Script_1.0.pcg.

 3. Select Next to proceed.

4. Verify that the package is present on your test Android device at the specified path from part 2, step 2: /sdcard/Download/

Part 3: Triggering JavaScript Script from Android Legacy Script  

 1. Once the package is available on the Android device, you can trigger the JavaScript scripts contained in the package by sending a legacy script to install the package which will trigger the JavaScript script to run.

installpackage %sdcard%/Download/"Triggering JavaScript Script from Android Legacy Script_1.0.pcg"

Verification and Validation

When you run the legacy script that is mentioned in part 3, step 1, you should see following pop-up message on your Android device. This message is displayed via JavaScript, as configured in part 1, step 6.

Was this helpful?