Created
February 10, 2016 23:09
-
-
Save oguzbabaoglu/180f83264f31d3cbee16 to your computer and use it in GitHub Desktop.
Custom AndroidJUnitRunner with wake lock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD; | |
import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; | |
import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON; | |
public class CustomJUnitRunner extends AndroidJUnitRunner { | |
@Override public void onCreate(Bundle arguments) { | |
super.onCreate(arguments); | |
ActivityLifecycleMonitorRegistry.getInstance().addLifecycleCallback(new ActivityLifecycleCallback() { | |
@Override public void onActivityLifecycleChanged(Activity activity, Stage stage) { | |
if (stage == Stage.PRE_ON_CREATE) { | |
activity.getWindow().addFlags(FLAG_DISMISS_KEYGUARD | FLAG_TURN_SCREEN_ON | FLAG_KEEP_SCREEN_ON); | |
} | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
Thank you for the code.
Can you tell me please how can I use it in Android Studio in a uiautomator test? or where shoudl I add this code?
Thank you for the help.
My best regards,
Mostafa