You can run UiAutomator from the application, you just need to have a test jar on the device and provide permissions for your application.
In your application, you can simply call:
uiautomator runtest Test.jar -c com.package.name.ClassName -e key value
And your device will do everything that your UiAutomatorTestCase will do.
Quick example:
Process rt = Runtime.getRuntime().exec("su"); DataOutputStream os = new DataOutputStream(rt.getOutputStream()); os.writeBytes("uiautomator runtest Testing.jar -c com.hey.rich.CalculatorDemo" + "\n"); os.flush(); os.writeBytes("exit\n");
tophernuts
source share