Take the 2-minute tour ×

I can lock my device with below code like

// Initialize Device Policy Manager service and our receiver class

devicePolicyManager =(DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
demoDeviceAdmin = new ComponentName(this, DemoDeviceAdminReceiver.class);


But once i did it (means lock my device in android by above code ) how can i open this lock programmatically in android whenever i required ? To lock a device i used background service so is there any solution to create any services to re-open a lock of my device ?

share|improve this question

2 Answers 2

Look at this:

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

Window window = getWindow();  
share|improve this answer

try this

 PowerManager pm = (PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE);
 PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE), "TAG");

I used this working for me.

share|improve this answer

Your Answer


