Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uiautomator "am start"

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.

like image 444
Laser Avatar asked Jul 30 '13 07:07

Laser


1 Answers

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.

like image 166
Gabriel Porumb Avatar answered Oct 12 '22 13:10

Gabriel Porumb