Skip to main content

hook

This tool on every surface: CLI · MCP · Python · JavaScript · Go · Java · .NET

Call a hook the app registered with Mobium's gray-box library, by name, and return what it answered — sign in, seed data, raise a toast: state set up without walking the UI. These call app_hook.

hook​

public Object hook(String name, String... args)

Calls a hook the app registered with Mobium's gray-box library, by name, and returns what it answered — sign in, seed data, raise a toast, without walking the UI. The app must have been launched with launchWithGrayBox. A name the app never registered is an InvalidArgumentException naming the ones it did.

@param name the hook's name, as the app registered it @param args the hook's arguments, in order @return what the hook returned, decoded from JSON

Examples​

Call a hook the app registered, and get back what it answered​

device.launchWithGrayBox("dev.mobium.mobiumapp");
Object answer = device.hook("raiseToast", "Toast raised by test script"); // "shown"

The same call from the command line, mobium hook raiseToast "Toast raised by test script", printed on an Android 15 emulator:

hook raiseToast answered: "shown"
gray box: the app was idle

mobium hook raiseToast "Toast raised by test script" on MobiumApp, Android 15 emulator, launched with --gray-box: the app's own toast says what the hook was sent

mobium hook raiseToast "Toast raised by test script" on MobiumApp, Android 15 emulator, launched with --gray-box: the app's own toast says what the hook was sent