本人在學習android uiautomator時遇到一個問題,有時候應用安裝使用過程當中遇到忽然彈出應用權限的安全警告致使運行中斷的狀況,在學習了監聽以後本身寫了一個監聽權限設置彈出框的的監聽,分享出來,請大神指正。java
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();//此行爲強制運行監聽,正常使用請刪除