Skip to content

Instantly share code, notes, and snippets.

@manijshrestha
Created October 30, 2014 03:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manijshrestha/62fe7f9755c9f265ae11 to your computer and use it in GitHub Desktop.
Save manijshrestha/62fe7f9755c9f265ae11 to your computer and use it in GitHub Desktop.
private void provisionOwner() {
DevicePolicyManager manager =
(DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
ComponentName componentName = BasicDeviceAdminReceiver.getComponentName(this);
if(!manager.isAdminActive(componentName)) {
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, componentName);
startActivityForResult(intent, 0);
return;
}
if (manager.isDeviceOwnerApp(getPackageName()))
manager.setLockTaskPackages(componentName, new String [] {getPackageName()});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment