Skip to content

Instantly share code, notes, and snippets.

@oguzbabaoglu
Created February 10, 2016 23:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oguzbabaoglu/180f83264f31d3cbee16 to your computer and use it in GitHub Desktop.
Save oguzbabaoglu/180f83264f31d3cbee16 to your computer and use it in GitHub Desktop.
Custom AndroidJUnitRunner with wake lock
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);
}
}
});
}
}
@mostafa1611
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment