Members
deleteListener
Removes the currently registered notification listener callback.
This function stops the previously set listener from receiving any further notification events. It is useful when you want to pause or clean up notification monitoring.
Note: If you want Total Control's computer client and script to get the content of each message, you must first activate the message service.
Example
// Callback function showMessage: output device name, app name, and message content
var { Notification } = require('sigma/notification');
function showMessage(dev, app, msg) {
print('device Name : ' + dev.getName());
print('app Name: ' + app);
print('msg : ' + msg);
}
// Create a notification object for all apps on any device
var notify = new Notification(tcConst.Any, tcConst.Any, tcConst.Any);
// Register the listener function
notify.setListener(showMessage);
// Later, remove the listener to stop receiving notifications
notify.deleteListener();
// If it executes successfully, it will stop printing any further notifications like:
device Name : HUAWEI-HUAWEI P7-L07
app Name: com.sigma_rt.totalcontrol
msg : Screenshot captured. Tap here to view.
device Name : HUAWEI-HUAWEI P7-L07
app Name: com.android.contacts
msg : 2 messages couldn't be sent
getNotification
Gets the content from the last getNotification to the current notification bar message.
The return value is an array of objects. Each object contains:
app (string): The package name of the app that generated the notification.
text (string): The content of the notification message.
device (Device): A Device object representing the source device.
Example
var { Notification } = require('sigma/notification');
// Create a notification bar message object for all messages for all apps on any device.
var notify = new Notification(tcConst.Any, tcConst.Any, tcConst.Any);
// Get the list of notification messages
var a = notify.getNotification();
// Print out each notification's details
if (a instanceof Array) {
for (var i = 0; i < a.length; i++) {
var app = a[i].app;
var text = a[i].text;
var device = a[i].device;
var deviceName = device.getName();
print("app :" + app);
print("text :" + text);
print("deviceName :" + deviceName);
}
}
// If it executes successfully, it will return:
app :com.sigma_rt.totalcontrol
text :Click enter application
deviceName :HUAWEI-HUAWEI P7-L07
app :com.huawei.systemmanager
text :TC is consuming power in the background. Touch here for details
deviceName :HUAWEI-HUAWEI P7-L07
reset
Clears the internal cache of previously captured notification messages.
After calling reset(), the next getNotification() call will return only new notifications
received since the reset. This method is useful for starting a fresh capture of new messages.
Example
var { Notification } = require('sigma/notification');
// Create a notification bar message object for all messages on any app from any device.
var notify = new Notification(tcConst.Any, tcConst.Any, tcConst.Any);
// Get the list of notification messages
var a = notify.getNotification();
// Print out each notification's details
if (a instanceof Array) {
for (var i = 0; i < a.length; i++) {
var app = a[i].app;
var text = a[i].text;
var device = a[i].device;
var deviceName = device.getName();
print("app :" + app);
print("text :" + text);
print("deviceName :" + deviceName);
}
}
// Reset the notification cache
notify.reset();
// If it executes successfully, it will return:
app :com.sigma_rt.totalcontrol
text :Click enter application
deviceName :HUAWEI-HUAWEI P7-L07
app :com.huawei.systemmanager
text :TC is consuming power in the background. Touch here for details
deviceName :HUAWEI-HUAWEI P7-L07
setApp
Sets the app match criteria for the message when creating a notification bar message object.
Example
var { Device } = require("sigma/device");
var { Notification } = require('sigma/notification');
// Get the current master device object
var sigmaDevice = Device.getMain();
// Define the APP name "com.tencent.mm"
var app = "com.tencent.mm";
// Match message conditions: any message
var match = tcConst.Any;
// Create notification object with no initial parameters
var notify = new Notification();
// Set the values of device, app, and match
notify.setDevice(sigmaDevice);
notify.setApp(app);
notify.setMatch(match);
// Now the notification object listens for any message from "com.tencent.mm" on the current device
setDevice
Sets the device match criteria for the message when creating a notification bar message object.
Example
var { Device } = require("sigma/device");
var { Notification } = require('sigma/notification');
// Get the current master device object
var sigmaDevice = Device.getMain();
// Define the APP name "com.tencent.mm"
var app = "com.tencent.mm";
// Match message conditions: any message
var match = tcConst.Any;
// Create notification object with no initial parameters
var notify = new Notification();
// Set the values of device, app, and match
notify.setDevice(sigmaDevice);
notify.setApp(app);
notify.setMatch(match);
// Now the notification object listens for any message from "com.tencent.mm" on the current device
setListener
Adds a listener function for real-time monitoring of notification bar messages.
The specified callback function is triggered whenever a matching notification is received.
The callback function should accept three parameters:
device: the Device object from which the notification originated
app: the package name of the app that generated the notification
msg: the content/text of the notification
Once registered, the listener will keep monitoring notifications until manually removed
via deleteListener() or the script is stopped.
Example
var { Notification } = require('sigma/notification');
// Callback function showMessage: outputs the device name, app name, and message content.
function showMessage(dev, app, msg) {
print('device Name : ' + dev.getName());
print('app Name: ' + app);
print('msg : ' + msg);
}
// Create a notification object that listens to all apps on any device.
var notify = new Notification(tcConst.Any, tcConst.Any, tcConst.Any);
// Register the listener function
notify.setListener(showMessage);
// If it executes successfully and matching notifications are received, it may output:
device Name : HUAWEI-HUAWEI P7-L07
app Name: com.sigma_rt.totalcontrol
msg : Screenshot captured. Tap here to view.
device Name : HUAWEI-HUAWEI P7-L07
app Name: com.android.contacts
msg : 2 messages couldn't be sent
setMatch
Sets the match criteria for the message content when creating a notification bar message object.
Example
var { Device } = require("sigma/device");
var { Notification } = require('sigma/notification');
// Get the current master device object
var sigmaDevice = Device.getMain();
// Define the APP name "com.tencent.mm"
var app = "com.tencent.mm";
// Match message conditions: any message
var match = tcConst.Any;
// Create notification object with no initial parameters
var notify = new Notification();
// Set the values of device, app, and match
notify.setDevice(sigmaDevice);
notify.setApp(app);
notify.setMatch(match);
// Now the notification object listens for any message from "com.tencent.mm" on the current device