在 UiAutomatorTestCase 中启动/绑定服务



我有一个UiAutomatorTestCase

public class MyUiTest extends UiAutomatorTestCase {   
   public void testMe() throws UiObjectNotFoundException {   
      getUiDevice().pressHome();
      //How can I start/bind a service in the test case?
      //Seems I am not able to get a context in UiAutomatorTestCase
   }
}

我想知道,是否可以在此类中使用startService(...)bindService(...)来启动/绑定服务?

您可以尝试使用:

Runtime.getRuntime().exec("am start -n package/activity");

上面的代码在 Android OS shell 中执行命令。这应该会启动一个应用程序。例如,要启动设置,您可以将包/活动替换为com.android.settings/。设置。

我不知道这是否是你要找的。你可以试一试。

最新更新