Mobile Development 2 min read

Using UiWatcher to Automatically Dismiss Android Security Warning Dialogs

The author encountered unexpected security‑warning pop‑ups during Android UIAutomator testing and created a UiWatcher that automatically clicks "Do not remind" and "Allow" to keep the test flow uninterrupted, sharing the full code for others to use.

FunTester
FunTester
FunTester
Using UiWatcher to Automatically Dismiss Android Security Warning Dialogs

The author was learning Android UiAutomator and sometimes the app installation process triggered a sudden security‑warning dialog that interrupted the test execution. After learning about watchers, they wrote a custom UiWatcher to detect the warning and automatically click the "Do not remind" and "Allow" buttons, then shared the implementation for feedback.

UiDevice.getInstance().registerWatcher("x1",new UiWatcher(){
        UiObject warrning = new UiObject(new UiSelector().text("安全警告"));
        @Override
        public boolean checkForCondition(){
        System.out.println("the watcher is begin !");
        if (warrning.exists()){
        UiObject noremind = new UiObject(new UiSelector().text("不再提醒"));
        try {
 noremind.click();
 } catch (UiObjectNotFoundException e1) {
 e1.printStackTrace();
 }
        UiObject allow = new UiObject(new UiSelector().text("允许"));
        try {
 allow.click();
 } catch (UiObjectNotFoundException e2) {
 e2.printStackTrace();
 }
        System.out.println("it is allow");
        return true;}
        System.out.println("it is refuse");
        return false;}});
UiObject ss = new UiObject(new UiSelector().text("扫啊扫"));
ss.click();
getUiDevice().runWatchers();//此行为强制运行监听,正常使用请删除

The post also includes a list of the author's previous technical articles for reference.

AndroidAutomationUiAutomatorMobileTestingSecurityWarningUiWatcher
FunTester
Written by

FunTester

10k followers, 1k articles | completely useless

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.