Code example for DevicePolicyManager

Methods: isAdminActive, removeActiveAdmin

0
	 */ 
	Boolean IsHaveDevicePolicyPermission()
	{ 
		ComponentName componentName;  
		componentName = new ComponentName(mContext, DeviceAdminSampleReceiver.class);  
		boolean active = mDevicePolicyManager.isAdminActive(componentName);  
		return active;
	} 
 
	/*!  
	 * \brief ³¢ÊÔÇëÇóDevicePolicyµÄ²Ù×÷ȨÏÞ 
	 */ 
	void TryHaveDevicePolicyPermission(Activity activity)
	{ 
		ComponentName componentName;  
		componentName = new ComponentName(activity, DeviceAdminSampleReceiver.class);  
		 // Æô¶¯É豸¹ÜÀí(ÒþʽIntent) - ÔÚAndroidManifest.xmlÖÐÉ趨ÏàÓ¦¹ýÂËÆ÷   
        Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);  
        //ȨÏÞÁÐ±í   
        intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, componentName);  
        //ÃèÊö(additional explanation)   
       //intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "------ ÆäËûÃèÊö ------");   
        activity.startActivityForResult(intent, 0);  
	} 
	 
	/*!  
	 * \brief ³¢ÊÔ È¡ÏûDevicePolicyµÄ²Ù×÷ȨÏÞ 
	 */ 
	void TryRemoveDevicePolicyPermission(Activity activity)
	{ 
		if (!IsHaveDevicePolicyPermission()) 
			return; 
		ComponentName componentName;  
		componentName = new ComponentName(activity, DeviceAdminSampleReceiver.class);  
		mDevicePolicyManager.removeActiveAdmin(componentName);
	} 
	 
	 public static class DeviceAdminSampleReceiver extends DeviceAdminReceiver {
	        void showToast(Context context, String msg) {
	            Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();