Application control module for Android devices in the Total Control scripting system.
This module enables automation and control of Android apps running on connected devices. It provides
functionality to launch, close, install, uninstall, and query apps, as well as manipulate or retrieve
activities on the device. It supports both Java-layer and JS-layer extensions to the Device object,
allowing methods to be invoked via device.runApp() or directly through exports.
Features
- Launch and restart applications by package name
- Close apps or check if an app is running in the foreground
- Retrieve the currently focused app or activity
- Install or uninstall APK files from a specified path
- Get a list of all installed packages on the device
- Dynamically open activities by component name with or without root
Usage Example
var app = require("sigma/app");
var { Device } = require('sigma/device');
var sigmaDevice = Device.getMain();
// Run an application
var result = sigmaDevice.runApp("com.tencent.qqmusic");
if (result === 0) {
print("App launched successfully");
}
// Get currently focused activity
var { getActivity } = require("sigma/app");
var activity = getActivity();
print("Current activity: " + activity);
Integration
- Methods are automatically bound to
Device.prototypeandDeviceArray.prototype
Functions
(inner) closeApp(packageName) → {number}
Close specified software on the device.
Example
var app = require("sigma/app");
var runAppName = "com.tencent.qqmusic";
var { Device } = require('sigma/device');
var sigmaDevice = Device.getMain();
var closeapp = sigmaDevice.closeApp(runAppName);
if (closeapp === 0) {
print("Succeed to close QQmusic");
} else {
print("Failed to close QQmusic");
}
// Operation Result:
// If it executes successfully, it will return:
Succeed to close QQmusic
Parameters:
| string | packageName |
The package name of the app to close, e.g. "com.tencent.qqmusic". |
Returns:
| number |
|
| string | null |
This function returns the value of the activity if it succeeds, and returns null if it fails. If failed, specific error information can be obtained by the lastError() function. |
| string | null |
This function returns the App package name if it succeeds, and returns null if it fails. If failed, specific error information can be obtained by the lastError() function. |
| object |
This function returns the name of all software installed on the phone if it succeeds, and returns null if it fails. If failed, specific error information can be obtained by the lastError() function. |
| string | apkPath |
The full file path to the APK file (e.g., "D:/Download/QQyinyue_850.apk"). |
Returns:
| number |
|
| string | packageName |
The package name of the application to check, e.g. "com.tencent.qqmusic". |
Returns:
| number |
Returns 0 if running in the foreground, otherwise returns non-zero. At this point, the lastError() function can be used to get the specific error message. |
| string | activity |
The full activity name in the format "package/class", e.g. "com.tencent.qqmusic/com.tencent.qqmusic.activity.AppStarterActivity". |
| boolean | administrator |
Whether to get super permissions. |
Returns:
| boolean |
This function returns true if it succeeds, and returns false if it fails. If failed, specific error information can be obtained by the lastError() function. |
| string | packageName |
The package name of the app to restart (e.g., "com.tencent.qqmusic"). |
Returns:
| boolean |
|
| string | packageName |
The package name of the app to run (e.g., "com.tencent.qqmusic"). |
Returns:
| number |
Returns |
| string | packageName |
The package name of the app to uninstall (e.g., "com.tencent.qqmusic"). |
Returns:
| number |
|