Uiautomator "am start"

android, android-uiautomator

Solution

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.

Problem

Does any body know how to call `am start -a ACTIVITY` from `uiautomator` code. Or is it possible to start activity right from `junit` code.

Original source