1

I need to show a lockscreen after 15 seconds of user inactivity. In my project I use ViewPager with three pages.

How can I check for inactive user action in all the three pages and all the elements on this pages?

Onik
  • 19,396
  • 14
  • 68
  • 91

2 Answers2

1

You could use a timer that shows a lockscreen after 15 secs of inactivity and zero its timing in the Activity's onUserInteraction() method.

Onik
  • 19,396
  • 14
  • 68
  • 91
0

You can do this :

WindowManager wm = Context.getSystemService(Context.WINDOW_SERVICE); //Get the context 

Window window = getWindow();  
window.addFlags(wm.LayoutParams.FLAG_DISMISS_KEYGUARD);  //Unlock the screen

DevicePolicyManager mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE); //Lock the screen

Note : you may need reference to an activity that can communicate with window.

check this link : link

Use handler for time :

new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
               // write you code 
           }
        }, 15000;//15sec
Abhinav Gupta
  • 2,225
  • 1
  • 14
  • 30