Disabling first-run greeter on fresh android emulator

心已入冬 提交于 2019-12-02 05:25:08

Have you tried using PackageManager.getLaunchIntentForPackage(..)? This will allow you to send the same Intent that the launcher uses to start your app. It should be equivalent to clicking on your application's launcher icon.

If you do need to go through the launcher, you can use a UiWatcher to dismiss the first-run overlay. Whenever UiAutomator can't find an element, it will call the checkForCondition(..) method for each registered UiWatcher and give you a chance to dismiss any overlays or dialogs that are getting in the way.

Apparently the greeter is called "cling". Searching though (rather old) code I found the following:

http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android-apps/4.0.2_r1/com/android/launcher2/Launcher.java#Launcher.isClingsEnabled%28%29

private boolean isClingsEnabled() {
    // TEMPORARY: DISABLE CLINGS ON LARGE UI
    if (LauncherApplication.isScreenLarge()) return false;
    // disable clings when running in a test harness
    if(ActivityManager.isRunningInTestHarness()) return false;
    return true;
}

And next stop is isRunningInTestHarness() at http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.0.2_r1/android/app/ActivityManager.java#ActivityManager.isRunningInTestHarness%28%29

public static boolean isRunningInTestHarness() {
    return SystemProperties.getBoolean("ro.test_harness", false);
}

Which in turn leads to adb shell setprop ro.test_harness true. Which just works.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!