Java 如何使用UIAutomator关闭快速设置系统面板?
在我的android测试中,我使用以下代码打开了快速设置面板:Java 如何使用UIAutomator关闭快速设置系统面板?,java,android,kotlin,android-uiautomator,Java,Android,Kotlin,Android Uiautomator,在我的android测试中,我使用以下代码打开了快速设置面板: device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) device.openQuickSettings() 现在如何关闭或向后滑动“快速设置”面板?即使没有明确关闭它的方法,您也可以使用UiDevice对象调用API>=16上的pressBack()方法。此模拟短按后退按钮(设备上的硬件后退按钮)以关闭快速设置。对于某些设备,需要两次
device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
device.openQuickSettings()
现在如何关闭或向后滑动“快速设置”面板?即使没有明确关闭它的方法,您也可以使用
UiDevice
对象调用API>=16上的pressBack()
方法。此模拟短按后退按钮(设备上的硬件后退按钮)以关闭快速设置。对于某些设备,需要两次pressBack()
呼叫。
例如:
//Initialize UiDevice object
var uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
//Open Quick Settings
uiDevice.openQuickSettings()
//Close the quick settings
uiDevice.pressBack()
/*
* If you will be using this test on multiple devices
* and don't know if you need to pressBack() twice then,
* You can check for an object with the Description of "Airplane mode"
* Which would mean quickSettings still partly open, so press back button again
*
* var pressAgain = false
* for (uiObj in uiDevice.findObjects(By.descContains("Airplane mode")))
* pressAgain = true
*/
//Devices require 2 calls to pressBack()
//if(pressAgain)
// uiDevice.pressBack()