Automation API

Android device automation

Event Callbacks

Utils

Network and toast event handlers

Access these methods through agent.utils. Register callbacks to receive system events during automation.

Note: For notification callbacks, see agent.notifications.

setNetworkCallback()

TypeScript
setNetworkCallback(callback: NetworkCallback | null): void

Registers a callback to receive network state changes. Pass null to unregister.

Parameters

NameTypeDescription
callback(networkAvailable: boolean) => voidCallback function or null to unregister

Examples

TypeScript
agent.utils.setNetworkCallback((networkAvailable) => {
if (!networkAvailable) {
console.log("Network disconnected!");
}
});

toastCallback

TypeScript
toastCallback: ((packageName: string, data: { message: string }) => void) | null

Set this property to receive toast messages shown by apps.

Example
TypeScript
agent.utils.toastCallback = (packageName, data) => {
console.log("Toast from", packageName + ":", data.message);
};

Callback Types

NetworkCallback

TypeScript
type NetworkCallback = (networkAvailable: boolean) => void;

ToastCallback

TypeScript
type ToastCallback = (
packageName: string,
data: { message: string }
) => void;