title: Android DevicePolicyManager lockNow()
body: <p>I'm new to Android development, that's why I hit a wall. I want an application to be running as a service, and monitors SMS. If a specific SMS message is received, it locks the phone (as if the lock period has expired). Kinda like a remote lock.</p>
  
  <p>I used the <code>DevicePolicyManager</code> to invoke the <code>lockNow()</code> method. However, it triggers an error right on the part <code>lockNow()</code> is called.</p>
  
  <p>Here's the sample code on the Activity:</p>
  
  <pre><code>public class SMSMessagingActivity extends Activity {
      /** Called when the activity is first created. */
  
  public static DevicePolicyManager mDPM;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);                    
  
      }
  
      public static void LockNow(){
          mDPM.lockNow();
      }
  
  }
  </code></pre>
  
  <p>I looked at <a href="http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/DeviceAdminSample.html" rel="nofollow">http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/DeviceAdminSample.html</a> as a reference example.</p>
  
  <p>Can anyone help me? Show me what's wrong with my code? Do I have to tweak something to enable Administrative Rights on the emulator or device?</p>
  
  <p>Thanks!</p>