Notification

notification~ Notification

new Notification(deviceopt, appopt, matchopt) → {object}

Create a notification bar message processing object.
This object can process messages for a specified device (collection), an specified application, and a specified condition.

You can create the object in three forms:

  1. new Notification(device, app, match) – Directly pass parameters on creation.
  2. new Notification() – Create first, then use setDevice, setApp, setMatch to assign values.
  3. new Notification(tcConst.Any, tcConst.Any, tcConst.Any) or new Notification()– Monitor all messages from all apps on all devices.

Note:
When a program on the phone receives a message, it usually displays the message in the notification bar of the phone.If you want Total Control's computer client and script to get the content of each message, we must first activate the message service.
Total Control mobile client activation message service steps:

  1. Open the Total Control mobile client software.
  2. Click the Settings button in the upper right corner.
  3. Click the [Setting message service] button in the [Message Setting] column, and check the radio button after the Total Control [TC notification listener service].
Example
// Example 1: Monitor "Hello" messages from WeChat on the main device.
var { Device } = require("sigma/device");
var { Notification } = require('sigma/notification');
// Get the current master device object
var sigmaDevice = Device.getMain();
var app = "com.tencent.mm";
var match = "[\\Hello\\]";
var notify = new Notification(sigmaDevice, app, match);

// Example 2: Monitor all messages from WeChat on the main device using set methods.
var { Device } = require("sigma/device");
var { Notification } = require('sigma/notification');
// Get the current master device object
var sigmaDevice = Device.getMain();
var app = "com.tencent.mm";
var match = tcConst.Any;
var notify = new Notification();
notify.setDevice(sigmaDevice);
notify.setApp(app);
notify.setMatch(match);

// Example 3: Monitor all messages from all apps on all devices.
var notify = new Notification();
// or
var notify = new Notification(tcConst.Any, tcConst.Any, tcConst.Any);
Parameters:
string device <optional>

A collection of device objects or device objects, depending on the device object obtained, any device with the constant value "tcConst.Any", for example: device = Device.connectAll() ;

Array | string app <optional>

(Optional) string: a single package name; string array: multiple package names; Any app can be expressed by "tcConst.Any";

Array | string match <optional>

(Optional) string: a single package name; string array: multiple package names; Any message is indicated by "tcConst.Any".

Returns:
object

Returns the notification bar message object if successful. If it fails, you can get the specific error message through the lastError() function.

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