RobotiumTech / robotium

Android UI Testing
http://www.robotium.org
Apache License 2.0
2.86k stars 786 forks source link

How to handle screenlock / power botton ? #864

Open sachinGirish opened 7 years ago

sachinGirish commented 7 years ago

How to handle screen lock/ power botton ? I have a test case that needs to lock screen and unlock screen, how i can handle it using robotium.

vikramuk commented 7 years ago

Hi Sachin, Try the keyevent 26 for power button

On 08-Feb-2017 7:14 PM, "Sachin G" notifications@github.com wrote:

How to handle screen lock/ power botton ? I have a test case that needs to lock screen and unlock screen, how i can handle it using robotium.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/RobotiumTech/robotium/issues/864, or mute the thread https://github.com/notifications/unsubscribe-auth/AEW59zZJkKwlh_czfjtu_Aw4chYLO8DPks5racbEgaJpZM4L61d1 .

sachinGirish commented 7 years ago

@vikramuk I tryed using keyevent but it not works.

I am able to unlock using activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);

Window window = this.getWindow(); window.addFlags(LayoutParams.FLAG_DISMISS_KEYGUARD); window.addFlags(LayoutParams.FLAG_SHOW_WHEN_LOCKED); window.addFlags(LayoutParams.FLAG_TURN_SCREEN_ON);

getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); is there any other specific code to lock screen.

Iam trying to use PARTIAL_WAKE_LOCK to lock but not getting it.

vikramuk commented 7 years ago

Is there any way you can add permission for keeping screen awake?. Then check keyevent for power button

Regards

On 09-Feb-2017 12:11 AM, "Sachin G" notifications@github.com wrote:

@vikramuk https://github.com/vikramuk I tryed using keyevent but it not works.

I am able to unlock using activity.getWindow().addFlags( WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);

Window window = this.getWindow(); window.addFlags(LayoutParams.FLAG_DISMISS_KEYGUARD); window.addFlags(LayoutParams.FLAG_SHOW_WHEN_LOCKED); window.addFlags(LayoutParams.FLAG_TURN_SCREEN_ON);

getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); is there any other specific code to lock screen.

Iam trying to use PARTIAL_WAKE_LOCK https://developer.android.com/reference/android/os/PowerManager.html to lock but not getting it.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/RobotiumTech/robotium/issues/864#issuecomment-278421943, or mute the thread https://github.com/notifications/unsubscribe-auth/AEW590ROj2qEb4O8yYJlz2PgQ3BVj_2qks5ragxygaJpZM4L61d1 .