Advertisement
Guest User

Untitled

a guest
Jun 9th, 2012
416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. Android DevicePolicyManager lockNow() problem
  2. public class SMSMessagingActivity extends Activity {
  3. /** Called when the activity is first created. */
  4.  
  5. public static DevicePolicyManager mDPM;
  6.  
  7. @Override
  8. public void onCreate(Bundle savedInstanceState) {
  9. super.onCreate(savedInstanceState);
  10. setContentView(R.layout.main);
  11.  
  12. mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
  13.  
  14. }
  15.  
  16. public static void LockNow(){
  17. mDPM.lockNow();
  18. }
  19.  
  20. }
  21.  
  22. ComponentName devAdminReceiver; // this would have been declared in your class body
  23. // then in your onCreate
  24. mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
  25. devAdminReceiver = new ComponentName(context, deviceAdminReceiver.class);
  26. //then in your onResume
  27.  
  28. boolean admin = mDPM.isAdminActive(devAdminReceiver);
  29. if (admin)
  30. mDPM.lockNow();
  31. else Log.i(tag,"Not an admin");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement