Does any body know how to callam start -a ACTIVITY
from uiautomator
code.
Or is it possible to start activity right from junit
code.
Here's an example I use to start an activity from the .jar file:
private boolean startSettings() {
try {
Runtime.getRuntime().exec(
"am start -n com.android.settings/.Settings");
sleep(1000);
} catch (IOException e) {
e.printStackTrace();
}
for (int i = 0; i < 5; i++) {
sleep(1000);
if (getUiDevice().getCurrentPackageName().contains(
"com.android.settings")) {
return true;
}
}
return false;
}
You can modify the code to start any app. You could also make the method more generic by adding a parameter for the package/ activity value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With