Unlock Android phone programmatically?

后端 未结 2 436
不知归路
不知归路 2021-01-12 20:16

I want to write the code on how to unlock the Android Phone programmatically.

I want lock or unlock the phone when the user taps the proximity sensor.



        
相关标签:
2条回答
  • 2021-01-12 20:44
    @Override
        protected void onResume() {
            // TODO Auto-generated method stub
            super.onResume();
             IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
                registerReceiver(mIntentReceiver, filter);
                System.out.println("BROADcast receiver registered****");
        }
    
         private BroadcastReceiver mIntentReceiver = new BroadcastReceiver(){
    
            @Override
            public void onReceive(Context context, Intent intent) {
                // TODO Auto-generated method stub
    
                    System.out.println("phone locked"); 
    
            }
    
    0 讨论(0)
  • 2021-01-12 20:51
    Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
                | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
                | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    

    An Alternative solution... try this to unlock the screen..

    0 讨论(0)
提交回复
热议问题