how to lock the android programatically

后端 未结 3 680
挽巷
挽巷 2021-01-17 02:12

i want to lock the phone when i click the lock button.anybody please help with simple code.i tried with part of code from API_Demos but it shows some error.

3条回答
  •  感动是毒
    2021-01-17 02:23

    @Bhupinder Kindly check the following link.

    http://musicm122.blogspot.in/2011/10/locking-and-unlocking-android-phone.html

    //Get the window from the context
    
       WindowManager wm = Context.getSystemService(Context.WINDOW_SERVICE);
    
       //Unlock
    
       //http://developer.android.com/reference/android/app/Activity.html#getWindow()
    
       Window window = getWindow();  
    
       window.addFlags(wm.LayoutParams.FLAG_DISMISS_KEYGUARD);  
    
    
    
       //Lock device
    
       DevicePolicyManager mDPM;
    
       mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
    

提交回复
热议问题