Skip to main content

Alert · AnswerAlert · PressAlertButton

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

Read a system dialog, or answer it. These call app_alert.

Alert​

public string Alert()

What a system dialog says, or an empty string when none is up. A permission prompt is another process's window, not the app's, and reading it needs no knowledge of what the buttons say.

AnswerAlert​

public void AnswerAlert(bool accept)
public void AnswerAlert(bool accept, string text)

Accepts or dismisses a dialog of one or two buttons: accept is yes and dismiss is no, so a two-button permission prompt is granted by accept and denied by dismiss, in any language. A dialog of three or more is refused, naming its buttons — more than one may mean yes, as on iOS's location prompt — so press one with PressAlertButton(string).

Types into a dialog's field, then accepts or dismisses it, in one call. A plain alert has no field, and the platform refuses the text. What accept and dismiss press is as for AnswerAlert(bool).

PressAlertButton​

public string PressAlertButton(string button)
public string PressAlertButton(int position)

Presses a dialog's button by its caption, on any dialog — one of three buttons or an app's own included — and returns the caption pressed. A caption matches in any case and with straight or curly quotes.

Presses a dialog's button by its position from 1, in the order the dialog shows them, which does not depend on the device's language; returns the caption pressed.

Examples​

Ask whether a dialog is up, what it says, and its buttons​

var text = device.Alert(); // empty when no dialog is up
if (text != "") Console.WriteLine(text);

The same call from the command line, mobium alert, printed on an Android 15 emulator:

a dialog is on screen: "Discard changes?\nThey will be lost."
buttons: "KEEP EDITING", "DISCARD"

mobium alert on an Android 15 emulator

mobium alert on an Android 15 emulator

Say yes to a dialog of one or two buttons​

device.AnswerAlert(true);

The same call from the command line, mobium alert accept, printed on an Android 15 emulator:

accepted the dialog "Discard changes?\nThey will be lost.": pressed "DISCARD"
BeforeAfter
Before: mobium alert accept on an Android 15 emulatorAfter: mobium alert accept on an Android 15 emulator

mobium alert accept on an Android 15 emulator

Press a button by its caption, on a dialog of three​

var pressed = device.PressAlertButton("Don't Save");
Console.WriteLine($"pressed {pressed}");

The same call from the command line, mobium alert --button "Don't Save", printed on an Android 15 emulator:

pressed "DON'T SAVE" on the dialog "Save this draft?\nYou can come back to it later."
BeforeAfter
Before: mobium alert --button "Don't Save" on an Android 15 emulatorAfter: mobium alert --button "Don't Save" on an Android 15 emulator

mobium alert --button "Don't Save" on an Android 15 emulator

More examples​

Fill a prompt's field and accept it, in one call​

device.AnswerAlert(true, "Groceries");