How to lock the device in a service?
<p>I have this code by which I can easily lock the device from an activity:</p>

<pre><code>WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.screenBrightness = 0;
        getWindow().setAttributes(lp);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
</code></pre>

<p>but I want to do this from a service or a broadcasrreciever so that if an sms is recieved the phon will be locked, but I cant solve this, any help?</p>
