本人在学习android uiautomator时遇到一个问题,有时候应用安装使用过程中遇到突然弹出应用权限的安全警告导致运行中断的情况,在学习了监听之后自己写了一个监听权限设置弹出框的的监听,分享出来,请大神指正。
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();//此行为强制运行监听,正常使用请删除