<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ComponentName Archives - Truiton</title>
	<atom:link href="https://www.truiton.com/tag/componentname/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>Technology Reaching Us In Time - Online</description>
	<lastBuildDate>Thu, 21 Nov 2019 12:47:04 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://i0.wp.com/www.truiton.com/wp-content/uploads/2022/11/cropped-truiton_new_logo_half_white.png?fit=32%2C32&#038;ssl=1</url>
	<title>ComponentName Archives - Truiton</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">54534495</site>	<item>
		<title>Android Device Administrator Example</title>
		<link>https://www.truiton.com/2014/01/android-device-administrator-example/</link>
					<comments>https://www.truiton.com/2014/01/android-device-administrator-example/#comments</comments>
		
		<dc:creator><![CDATA[Mohit Gupt]]></dc:creator>
		<pubDate>Sun, 12 Jan 2014 16:55:24 +0000</pubDate>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[ComponentName]]></category>
		<category><![CDATA[Device Administration API]]></category>
		<category><![CDATA[Device Management Policies]]></category>
		<category><![CDATA[DevicePolicyManager]]></category>
		<guid isPermaLink="false">http://www.truiton.com/?p=575</guid>

					<description><![CDATA[<p>Building an enterprise level app for android could have never been easier. With this Android Device Administrator Example, I would explain how to detect active Android device policy managers. As I explained in my previous tutorial about Android DevicePolicyManager that Android has an inbuilt framework to implement device administration policies. With help of these policies&#8230;&#160;<a href="https://www.truiton.com/2014/01/android-device-administrator-example/" rel="bookmark">Read More &#187;<span class="screen-reader-text">Android Device Administrator Example</span></a></p>
<p>The post <a href="https://www.truiton.com/2014/01/android-device-administrator-example/">Android Device Administrator Example</a> appeared first on <a href="https://www.truiton.com">Truiton</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<div class="wp-block-image"><figure class="aligncenter"><img data-recalc-dims="1" fetchpriority="high" decoding="async" width="640" height="450" data-attachment-id="580" data-permalink="https://www.truiton.com/2014/01/android-device-administrator-example/android-security/" data-orig-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/Android-Device-Administrator.jpg?fit=640%2C450&amp;ssl=1" data-orig-size="640,450" data-comments-opened="1" data-image-title="Android Security" data-image-description="&lt;p&gt;3d illustration of a large padlock attached to a metallic green and silver Google Android logo over a dark reflective surface&lt;/p&gt;
" data-image-caption="" data-large-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/Android-Device-Administrator.jpg?fit=640%2C450&amp;ssl=1" src="https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/Android-Device-Administrator.jpg?resize=640%2C450" alt="Android Device Administrator" class="wp-image-580" srcset="https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/Android-Device-Administrator.jpg?w=640&amp;ssl=1 640w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/Android-Device-Administrator.jpg?resize=300%2C210&amp;ssl=1 300w" sizes="(max-width: 640px) 100vw, 640px" /></figure></div>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Building an enterprise level app for android could have never been easier. With this Android Device Administrator Example, I would explain how to detect active Android device policy managers. As I explained in my previous tutorial about <a title="Android DevicePolicyManager Example" href="http://www.truiton.com/2014/01/android-devicepolicymanager-example/" target="_blank" rel="noopener noreferrer">Android DevicePolicyManager</a> that Android has an inbuilt framework to implement device administration policies. With help of these policies one can force a device to have security features like passwords with quality parameters, and to count the failed attempts for a password. Also you can disable the device camera with Android Device Administrator.</p>



<p class="wp-block-paragraph">The way I visioned the working of Android Device Administration APIs for enterprise apps, was that they would come in a bunch where one app would be a device admin, implementing the policies on a device. While other apps would just check if the appropriate policy has been implemented or not. If not not then the access to those apps would be denied. For better understanding I divided the tutorial into two parts, in the first part I showed how to implement DevicePolicyManager class and in this second part I would show how to detect the active device admin:</p>



<ol class="wp-block-list"><li><a title="Android DevicePolicyManager Example" href="http://www.truiton.com/2014/01/android-devicepolicymanager-example/">Android DevicePolicyManager Example</a></li><li><a title="Android Device Administrator Example" href="http://www.truiton.com/2014/01/android-device-administrator-example/">Android Device Administrator Example</a></li></ol>



<p class="wp-block-paragraph"></p>



<h2 class="wp-block-heading">1. Android DevicePolicyManager</h2>



<p class="wp-block-paragraph">Again before moving ahead with the <a title="Android Device Administrator Example" href="http://www.truiton.com/2014/01/android-device-administrator-example/">Android Device Administrator Example</a> I would like to give a brief intro to Android DevicePolicy Manager class. Android <a title="Android Device Policy Manager" href="http://developer.android.com/reference/android/app/admin/DevicePolicyManager.html" target="_blank" rel="noopener noreferrer">DevicePolicyManager </a>class is a class used to implement security policies on a device. These policies could be anything like, that a device should have a password, a policy can define the minimum length of a password, no of special characters etc. With a policy we can also disable camera, wipe user data, watch failed password attempts and also encrypt user data. For all this please read my first tutorial in this Android Device Administrator series where an implementation of Android <a title="Android DeviceAdminReceiver" href="http://developer.android.com/reference/android/app/admin/DeviceAdminReceiver.html" target="_blank" rel="noopener noreferrer">DeviceAdminReceiver</a> is shown with DevicePolicyManager.</p>



<p class="wp-block-paragraph"></p>



<h2 class="wp-block-heading">2. Android Device Administrator APIs</h2>



<p class="wp-block-paragraph">In Android you can make your own Device Administrator with help of DevicePolicyManager class but now the task at hand is to detect the active Android Device Administrator through APIs. If you remember the package name that I used in my previous tutorial was <em>com.truiton.devicepolicymanager</em>. Now I would show how to detect if device administrator with this package name is active. To do that in a separate app please define the class as defined below:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">package com.truiton.activedevicepolicy;

import java.util.List;

import android.os.Bundle;
import android.app.Activity;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.util.Log;
import android.view.Menu;

public class ActiveDevicePolicy extends Activity {
	private DevicePolicyManager activeDevicePolicyManager;
	private final String LOG_TAG = "ActiveDevicePolicy";
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_active_device_policy);
		activeDevicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
		List&lt;ComponentName> activeAdmins = activeDevicePolicyManager.getActiveAdmins();
		if(activeAdmins != null &amp;&amp; !activeAdmins.isEmpty()){
			for(int index = 0; index &lt; activeAdmins.size(); index++ ){
				Log.i(LOG_TAG, "flattenToShortString: "+ activeAdmins.get(index).flattenToShortString());
				Log.i(LOG_TAG, "flattenToString: "+ activeAdmins.get(index).flattenToString());
				Log.i(LOG_TAG, "getClassName: "+ activeAdmins.get(index).getClassName());
				Log.i(LOG_TAG, "getPackageName: "+ activeAdmins.get(index).getPackageName());
				Log.i(LOG_TAG, "getShortClassName: "+ activeAdmins.get(index).getShortClassName());
				Log.i(LOG_TAG, "toShortString: "+ activeAdmins.get(index).toShortString());		
			}
		} else {
			Log.i(LOG_TAG, "No Active Device Policy Manager");
		}
	}

}</pre>



<p class="wp-block-paragraph">In the above code I have called <em>DevicePolicyManager.getActiveAdmins()</em> method to retrieve the list of all the admins that are active at the moment. Now the interesting part here is that, since its returning a list; there could be more than one device admins in that list. <span style="text-decoration: underline;">The implied point here is that YES there can be more than one active&nbsp;Android Device Administrators on a device at a time but, keep in mind the strictest policy remains active.</span></p>



<p class="wp-block-paragraph">In the above code, <em>ComponentName.getPackageName()</em> method is used to get the package name. Now since we know what package name we are looking for i.e. <em>com.truiton.devicepolicymanager</em> we can easily identify that, if the intended Android Device Administrator is active. Please have a look at the screenshot of logs:</p>



<div class="wp-block-image"><figure class="aligncenter"><img data-recalc-dims="1" decoding="async" width="962" height="190" data-attachment-id="578" data-permalink="https://www.truiton.com/2014/01/android-device-administrator-example/android-device-administrator-api/" data-orig-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/Android-Device-Administrator-API.png?fit=962%2C190&amp;ssl=1" data-orig-size="962,190" data-comments-opened="1" data-image-title="Android Device Administrator API" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/Android-Device-Administrator-API.png?fit=962%2C190&amp;ssl=1" src="https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/Android-Device-Administrator-API.png?resize=962%2C190" alt="Android Device Administrator API" class="wp-image-578" srcset="https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/Android-Device-Administrator-API.png?w=962&amp;ssl=1 962w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/Android-Device-Administrator-API.png?resize=300%2C59&amp;ssl=1 300w" sizes="(max-width: 962px) 100vw, 962px" /></figure></div>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">With this I would sum up Android Device Administrator Example by saying you can create an app with which you can implement device administration policies. And create a separate app where you can detect those policies and do the desired function on your secure device. Although if you want a single app where you define policies, activate them and use them, that&#8217;s also possible <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /> . Hope this helps you, if it did please share it with your friends on Facebook, Google+ and also like our Facebook page to get our updates.</p>
<div class="saboxplugin-wrap" itemtype="http://schema.org/Person" itemscope itemprop="author"><div class="saboxplugin-tab"><div class="saboxplugin-gravatar"><img alt='Mohit Gupt' src='https://secure.gravatar.com/avatar/a816092ad56645d2635ccfceb9f7e9d44821c19dec126cb394c882ba574eaa04?s=100&#038;d=mm&#038;r=g' srcset='https://secure.gravatar.com/avatar/a816092ad56645d2635ccfceb9f7e9d44821c19dec126cb394c882ba574eaa04?s=200&#038;d=mm&#038;r=g 2x' class='avatar avatar-100 photo' height='100' width='100' itemprop="image"/></div><div class="saboxplugin-authorname"><a href="https://www.truiton.com/author/mohitgupt/" class="vcard author" rel="author"><span class="fn">Mohit Gupt</span></a></div><div class="saboxplugin-desc"><div itemprop="description"><p>Born in New Delhi, India. A software engineer by profession, an android enthusiast and mobile development evangelist. My motive here is to create a group of skilled engineers, who can build better software. Reason being programming is my passion, and also it feels good to make a device do something you want. Professionally I have worked with many software engineering and product development firms. As of now too, I am employed as a senior engineer in a leading tech company. In total I may have worked on more than 20 projects professionally, but whenever I get spare time I share my thoughts here at Truiton.</p>
</div></div><div class="saboxplugin-web "><a href="http://www.truiton.com" target="_self" >www.truiton.com</a></div><div class="clearfix"></div><div class="saboxplugin-socials "><a title="Wordpress" target="_blank" href="https://www.truiton.com/author/mohitgupt/" rel="nofollow noopener" class="saboxplugin-icon-grey"><svg aria-hidden="true" class="sab-wordpress" role="img" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 512 512"><path fill="currentColor" d="M61.7 169.4l101.5 278C92.2 413 43.3 340.2 43.3 256c0-30.9 6.6-60.1 18.4-86.6zm337.9 75.9c0-26.3-9.4-44.5-17.5-58.7-10.8-17.5-20.9-32.4-20.9-49.9 0-19.6 14.8-37.8 35.7-37.8.9 0 1.8.1 2.8.2-37.9-34.7-88.3-55.9-143.7-55.9-74.3 0-139.7 38.1-177.8 95.9 5 .2 9.7.3 13.7.3 22.2 0 56.7-2.7 56.7-2.7 11.5-.7 12.8 16.2 1.4 17.5 0 0-11.5 1.3-24.3 2l77.5 230.4L249.8 247l-33.1-90.8c-11.5-.7-22.3-2-22.3-2-11.5-.7-10.1-18.2 1.3-17.5 0 0 35.1 2.7 56 2.7 22.2 0 56.7-2.7 56.7-2.7 11.5-.7 12.8 16.2 1.4 17.5 0 0-11.5 1.3-24.3 2l76.9 228.7 21.2-70.9c9-29.4 16-50.5 16-68.7zm-139.9 29.3l-63.8 185.5c19.1 5.6 39.2 8.7 60.1 8.7 24.8 0 48.5-4.3 70.6-12.1-.6-.9-1.1-1.9-1.5-2.9l-65.4-179.2zm183-120.7c.9 6.8 1.4 14 1.4 21.9 0 21.6-4 45.8-16.2 76.2l-65 187.9C426.2 403 468.7 334.5 468.7 256c0-37-9.4-71.8-26-102.1zM504 256c0 136.8-111.3 248-248 248C119.2 504 8 392.7 8 256 8 119.2 119.2 8 256 8c136.7 0 248 111.2 248 248zm-11.4 0c0-130.5-106.2-236.6-236.6-236.6C125.5 19.4 19.4 125.5 19.4 256S125.6 492.6 256 492.6c130.5 0 236.6-106.1 236.6-236.6z"></path></svg></span></a><a title="Twitter" target="_blank" href="http://twitter.com/mohitgupt" rel="nofollow noopener" class="saboxplugin-icon-grey"><svg aria-hidden="true" class="sab-twitter" role="img" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 30 30"><path d="M26.37,26l-8.795-12.822l0.015,0.012L25.52,4h-2.65l-6.46,7.48L11.28,4H4.33l8.211,11.971L12.54,15.97L3.88,26h2.65 l7.182-8.322L19.42,26H26.37z M10.23,6l12.34,18h-2.1L8.12,6H10.23z" /></svg></span></a><a title="Facebook" target="_blank" href="https://www.facebook.com/Mr.Mohit.Gupt" rel="nofollow noopener" class="saboxplugin-icon-grey"><svg aria-hidden="true" class="sab-facebook" role="img" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 264 512"><path fill="currentColor" d="M76.7 512V283H0v-91h76.7v-71.7C76.7 42.4 124.3 0 193.8 0c33.3 0 61.9 2.5 70.2 3.6V85h-48.2c-37.8 0-45.1 18-45.1 44.3V192H256l-11.7 91h-73.6v229"></path></svg></span></a></div></div></div><p>The post <a href="https://www.truiton.com/2014/01/android-device-administrator-example/">Android Device Administrator Example</a> appeared first on <a href="https://www.truiton.com">Truiton</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.truiton.com/2014/01/android-device-administrator-example/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">575</post-id>	</item>
		<item>
		<title>Android DevicePolicyManager Example</title>
		<link>https://www.truiton.com/2014/01/android-devicepolicymanager-example/</link>
					<comments>https://www.truiton.com/2014/01/android-devicepolicymanager-example/#comments</comments>
		
		<dc:creator><![CDATA[Mohit Gupt]]></dc:creator>
		<pubDate>Sat, 11 Jan 2014 20:35:49 +0000</pubDate>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[ComponentName]]></category>
		<category><![CDATA[Device Management Policies]]></category>
		<category><![CDATA[DeviceAdminReceiver]]></category>
		<category><![CDATA[Security]]></category>
		<guid isPermaLink="false">http://www.truiton.com/?p=556</guid>

					<description><![CDATA[<p>Its always good to learn new things in the area of your interest. Recently while mucking around Android I came across the Android DevicePolicyManager class. After making a few searches here and there I found out its a very powerful concept of android and could make a device really secure. One should never underestimate Android,&#8230;&#160;<a href="https://www.truiton.com/2014/01/android-devicepolicymanager-example/" rel="bookmark">Read More &#187;<span class="screen-reader-text">Android DevicePolicyManager Example</span></a></p>
<p>The post <a href="https://www.truiton.com/2014/01/android-devicepolicymanager-example/">Android DevicePolicyManager Example</a> appeared first on <a href="https://www.truiton.com">Truiton</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<div class="wp-block-image"><figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="640" height="428" data-attachment-id="569" data-permalink="https://www.truiton.com/2014/01/android-devicepolicymanager-example/locked-heart/" data-orig-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/11434605616_7abaf074c5_z.jpg?fit=640%2C428&amp;ssl=1" data-orig-size="640,428" data-comments-opened="1" data-image-title="Locked heart" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/11434605616_7abaf074c5_z.jpg?fit=640%2C428&amp;ssl=1" src="https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/11434605616_7abaf074c5_z.jpg?resize=640%2C428" alt="Android DevicePolicyManager" class="wp-image-569" srcset="https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/11434605616_7abaf074c5_z.jpg?w=640&amp;ssl=1 640w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/11434605616_7abaf074c5_z.jpg?resize=300%2C200&amp;ssl=1 300w" sizes="auto, (max-width: 640px) 100vw, 640px" /></figure></div>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Its always good to learn new things in the area of your interest. Recently while mucking around Android I came across the Android DevicePolicyManager class. After making a few searches here and there I found out its a very powerful concept of android and could make a device really secure. One should never underestimate Android, its full of numerous useful features. This <a title="Android Device Policy Manager" href="http://developer.android.com/reference/android/app/admin/DevicePolicyManager.html" target="_blank" rel="noopener noreferrer">Android DevicePolicyManager</a> class could be a very useful concept for enterprise level applications.</p>



<p class="wp-block-paragraph">I always used to toy with the idea of enterprise level apps for android, but the thing which always stopped me was enterprise level security. But with these device administration APIs its very simple for an app to implement some device level security policies which can be a savior incase of security breach, and in worst case a device wipe. Now since this Android DevicePolicyManager is a class which works in conjunction with two more classes <a title="Android DeviceAdminReceiver" href="http://developer.android.com/reference/android/app/admin/DeviceAdminReceiver.html" target="_blank" rel="noopener noreferrer">DeviceAdminReceiver</a>, and <a title="Android ComponentName" href="http://developer.android.com/reference/android/content/ComponentName.html" target="_blank" rel="noopener noreferrer">ComponentName</a>, this is going to be a long tutorial hence I&#8217;ll be splitting it into two parts:</p>



<ol class="wp-block-list"><li><a title="Android DevicePolicyManager Example" href="http://www.truiton.com/2014/01/android-devicepolicymanager-example/">Android DevicePolicyManager Example</a></li><li><a title="Android Device Administrator Example" href="http://www.truiton.com/2014/01/android-device-administrator-example/" target="_blank" rel="noopener noreferrer">Android Device Administrator Example</a></li></ol>



<p class="wp-block-paragraph">Here in the first part <a title="Android DevicePolicyManager Example" href="http://www.truiton.com/2014/01/android-devicepolicymanager-example/">Android DevicePolicyManager Example</a> I would explain how to implement the DevicePolicyManager and in the second part I would make a separate app where we could detect these policies. The way I picture it: enterprise level apps would come in a bunch, one app would implement all the device management policies and all other apps would only run if those polices are accepted by user.</p>



<p class="wp-block-paragraph">Now since this is a sort of security implementation, hence most of the code in this app would be at back-end, resulting a simple UI, where a check box would be used to activate the Android DevicePolicyManager. Please have a look at the screen shot and its layout file:</p>



<div class="wp-block-image"><figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="425" height="755" data-attachment-id="563" data-permalink="https://www.truiton.com/2014/01/android-devicepolicymanager-example/devicepolicymanager1/" data-orig-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/DevicePolicyManager1.png?fit=425%2C755&amp;ssl=1" data-orig-size="425,755" data-comments-opened="1" data-image-title="DevicePolicyManager1" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/DevicePolicyManager1.png?fit=425%2C755&amp;ssl=1" src="https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/DevicePolicyManager1.png?resize=425%2C755" alt="Android DevicePolicyManager" class="wp-image-563"/></figure></div>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".DevicePolicyAdmin" >

    &lt;ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:scaleType="centerCrop"
        android:src="@drawable/logo" />

    &lt;View
        android:id="@+id/line"
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:layout_below="@+id/imageView1"
        android:background="#000000" />

    &lt;CheckBox
        android:id="@+id/checkBox1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/line"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="15dp"
        android:text="Truiton Device Admin Enabled"
        android:textStyle="bold" />

&lt;/RelativeLayout></pre>



<p class="wp-block-paragraph"></p>



<h2 class="wp-block-heading">1. Device Management Policies</h2>



<p class="wp-block-paragraph">To start off, the first thing that should be discussed is the device management polices. In this&nbsp;Android DevicePolicyManager Example I am going to implement these six policies:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;device-admin xmlns:android="http://schemas.android.com/apk/res/android">
  &lt;uses-policies>
    &lt;limit-password />
    &lt;watch-login />
    &lt;force-lock />
    &lt;wipe-data />
    &lt;expire-password />
    &lt;disable-camera />
  &lt;/uses-policies>
&lt;/device-admin></pre>



<p class="wp-block-paragraph">The above stated file is an xml file stating your app&#8217;s device administration policies. This file should be saved in your <strong>res/xml</strong> folder by the name of your choice, I named it <strong>device_policies.xml</strong>. Now since the names for device admin policies are self<br>explanatory I would give a detailed explanation to these policies in a later step. For now lets move on to next step i.e. defining Manifest, and declaring Android DeviceAdminReceiver.</p>



<p class="wp-block-paragraph"></p>



<h2 class="wp-block-heading">2. Android DeviceAdminReceiver</h2>



<p class="wp-block-paragraph">Before declaring Android DeviceAdminReceiver we need to define it in our manifest file, please have a look:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="xml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;?xml version="1.0" encoding="utf-8"?>
&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.truiton.devicepolicymanager"
    android:versionCode="1"
    android:versionName="1.0" >

    &lt;uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    &lt;application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        &lt;activity
            android:name="com.truiton.devicepolicymanager.DevicePolicyAdmin"
            android:label="@string/app_name" >
            &lt;intent-filter>
                &lt;action android:name="android.intent.action.MAIN" />

                &lt;category android:name="android.intent.category.LAUNCHER" />
            &lt;/intent-filter>
        &lt;/activity>

        &lt;receiver
            android:name="com.truiton.devicepolicymanager.DevicePolicyAdmin$MyDevicePolicyReceiver"
            android:description="@string/device_admin_description"
            android:label="@string/device_admin"
            android:permission="android.permission.BIND_DEVICE_ADMIN" >
            &lt;meta-data
                android:name="android.app.device_admin"
                android:resource="@xml/device_policies" />

            &lt;intent-filter>
                &lt;action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
                &lt;action android:name="android.app.action.DEVICE_ADMIN_DISABLE_REQUESTED" />
                &lt;action android:name="android.app.action.DEVICE_ADMIN_DISABLED" />
                &lt;action android:name="android.app.action.ACTION_PASSWORD_CHANGED" />
                &lt;action android:name="android.app.action.ACTION_PASSWORD_EXPIRING" />
                &lt;action android:name="android.app.action.ACTION_PASSWORD_FAILED" />
                &lt;action android:name="android.app.action.ACTION_PASSWORD_SUCCEEDED" />
            &lt;/intent-filter>
        &lt;/receiver>
    &lt;/application>

&lt;/manifest></pre>



<p class="wp-block-paragraph">Here in this manifest file the main things to notice are:</p>



<ol class="wp-block-list"><li>The <em>android.permission.BIND_DEVICE_ADMIN</em> permission, as through this permission your receiver can listen to system broadcasts.</li><li>The <em>meta-data</em> block where your XML file stating your policies is referenced, in my case device_policies.xml.</li><li>The <em>intent-filter</em> block as this is the block which defines the intents which would be listened by our device DeviceAdminReciever.</li></ol>



<p class="wp-block-paragraph">Also have a look at the strings.xml:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="xml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;?xml version="1.0" encoding="utf-8"?>
&lt;resources>

    &lt;string name="app_name">Device Policy Manager&lt;/string>
    &lt;string name="action_settings">Settings&lt;/string>
    &lt;string name="hello_world">Hello world!&lt;/string>
    &lt;string name="device_admin">Truiton Device Admin&lt;/string>
    &lt;string name="device_admin_description">Truiton\'s device admin implementation which shows the usage of DevicePolicyManager class.  This implementation provides you a way to control a device\'s security.&lt;/string>
    &lt;string name="admin_explanation">Truiton Device Admin helps the user to get special privileges, for eg. to access the Truiton network data. These privileges can only be acquired by accepting these policies.&lt;/string>
&lt;/resources></pre>



<p class="wp-block-paragraph">Now that we are ready with the manifest and strings lets have a look at the Android DeviceAdminReceiver:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">	public static class MyDevicePolicyReceiver extends DeviceAdminReceiver {

		@Override
		public void onDisabled(Context context, Intent intent) {
			Toast.makeText(context, "Truiton's Device Admin Disabled",
					Toast.LENGTH_SHORT).show();
		}

		@Override
		public void onEnabled(Context context, Intent intent) {
			Toast.makeText(context, "Truiton's Device Admin is now enabled",
					Toast.LENGTH_SHORT).show();
		}

		@Override
		public CharSequence onDisableRequested(Context context, Intent intent) {
			CharSequence disableRequestedSeq = "Requesting to disable Device Admin";
			return disableRequestedSeq;
		}

		@TargetApi(Build.VERSION_CODES.HONEYCOMB)
		@Override
		public void onPasswordChanged(Context context, Intent intent) {
			Toast.makeText(context, "Device password is now changed",
					Toast.LENGTH_SHORT).show();
			DevicePolicyManager localDPM = (DevicePolicyManager) context
					.getSystemService(Context.DEVICE_POLICY_SERVICE);
			ComponentName localComponent = new ComponentName(context,
					MyDevicePolicyReceiver.class);
			localDPM.setPasswordExpirationTimeout(localComponent, 0L);
		}

		@TargetApi(Build.VERSION_CODES.HONEYCOMB)
		@Override
		public void onPasswordExpiring(Context context, Intent intent) {
			// This would require API 11 an above
			Toast.makeText(
					context,
					"Truiton's Device password is going to expire, please change to a new password",
					Toast.LENGTH_LONG).show();

			DevicePolicyManager localDPM = (DevicePolicyManager) context
					.getSystemService(Context.DEVICE_POLICY_SERVICE);
			ComponentName localComponent = new ComponentName(context,
					MyDevicePolicyReceiver.class);
			long expr = localDPM.getPasswordExpiration(localComponent);
			long delta = expr - System.currentTimeMillis();
			boolean expired = delta &lt; 0L;
			if (expired) {
				localDPM.setPasswordExpirationTimeout(localComponent, 10000L);
				Intent passwordChangeIntent = new Intent(
						DevicePolicyManager.ACTION_SET_NEW_PASSWORD);
				passwordChangeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				context.startActivity(passwordChangeIntent);
			}
		}

		@Override
		public void onPasswordFailed(Context context, Intent intent) {
			Toast.makeText(context, "Password failed", Toast.LENGTH_SHORT)
					.show();
		}

		@Override
		public void onPasswordSucceeded(Context context, Intent intent) {
			Toast.makeText(context, "Access Granted", Toast.LENGTH_SHORT)
					.show();
		}

		@Override
		public void onReceive(Context context, Intent intent) {
			Log.i(LOG_TAG,
					"MyDevicePolicyReciever Received: " + intent.getAction());
			super.onReceive(context, intent);
		}
	}</pre>



<p class="wp-block-paragraph">Have a look at the <em>DeviceAdminReceiver.onPasswordExpiring</em> method, here I have implemented a logic by the help of&nbsp;Android DevicePolicyManager class to increase the expiring password by ten seconds and prompt the user to change it immediately. Now untill the password is set it would keep on prompting to set the password.&nbsp; Once the password is set then the <em>PasswordExpirationTimeout</em> is set to zero, which implies that this password wont expire.</p>



<p class="wp-block-paragraph"></p>



<h2 class="wp-block-heading">3. Android DevicePolicyManager</h2>



<p class="wp-block-paragraph">Android DevicePolicyManager is a unique class through which an app can implement some special policies on the device it is installed. These polices could be anything, like device should have a password. You can also set rules for that password like number of digits in it, number of special characters etc.&nbsp;Number of retries for failed password attempts. Another great device admin policy that you can implement is to wipe out user data in-case of failed password attempts. As I said Android DevicePolicyManager is a powerful class, therefore it also gives you the ability to disable device&#8217;s camera. To make all this happen, all you need to do; is make the user accept and activate these policies. lets have a look at the complete&nbsp;DevicePolicyAdmin class:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">package com.truiton.devicepolicymanager;

import android.os.Build;
import android.os.Bundle;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.admin.DeviceAdminReceiver;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.Toast;

public class DevicePolicyAdmin extends Activity {
	private final static String LOG_TAG = "DevicePolicyAdmin";
	DevicePolicyManager truitonDevicePolicyManager;
	ComponentName truitonDevicePolicyAdmin;
	private CheckBox truitonAdminEnabledCheckbox;
	protected static final int REQUEST_ENABLE = 1;
	protected static final int SET_PASSWORD = 2;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_device_policy_admin);
		truitonDevicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
		truitonDevicePolicyAdmin = new ComponentName(this,
				MyDevicePolicyReceiver.class);

		truitonAdminEnabledCheckbox = (CheckBox) findViewById(R.id.checkBox1);
	}

	@Override
	protected void onResume() {
		super.onResume();
		if (isMyDevicePolicyReceiverActive()) {
			truitonAdminEnabledCheckbox.setChecked(true);
		} else {
			truitonAdminEnabledCheckbox.setChecked(false);
		}
		truitonAdminEnabledCheckbox
		.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(CompoundButton buttonView,
					boolean isChecked) {
				if (isChecked) {
					Intent intent = new Intent(
							DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
					intent.putExtra(
							DevicePolicyManager.EXTRA_DEVICE_ADMIN,
							truitonDevicePolicyAdmin);
					intent.putExtra(
							DevicePolicyManager.EXTRA_ADD_EXPLANATION,
							getString(R.string.admin_explanation));
					startActivityForResult(intent, REQUEST_ENABLE);
				} else {
					truitonDevicePolicyManager
							.removeActiveAdmin(truitonDevicePolicyAdmin);
				}
			}
		});
	}

	@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if (resultCode == RESULT_OK) {
			switch (requestCode) {
			case REQUEST_ENABLE:
				Log.v(LOG_TAG, "Enabling Policies Now");
				truitonDevicePolicyManager.setMaximumTimeToLock(
						truitonDevicePolicyAdmin, 30000L);
				truitonDevicePolicyManager.setMaximumFailedPasswordsForWipe(
						truitonDevicePolicyAdmin, 5);
				truitonDevicePolicyManager.setPasswordQuality(
						truitonDevicePolicyAdmin,
						DevicePolicyManager.PASSWORD_QUALITY_COMPLEX);
				truitonDevicePolicyManager.setCameraDisabled(
						truitonDevicePolicyAdmin, true);
				boolean isSufficient = truitonDevicePolicyManager
						.isActivePasswordSufficient();
				if (isSufficient) {
					truitonDevicePolicyManager.lockNow();
				} else {
					Intent setPasswordIntent = new Intent(
							DevicePolicyManager.ACTION_SET_NEW_PASSWORD);
					startActivityForResult(setPasswordIntent, SET_PASSWORD);
					truitonDevicePolicyManager.setPasswordExpirationTimeout(
							truitonDevicePolicyAdmin, 10000L);
				}
				break;
			}
		}
	}

	private boolean isMyDevicePolicyReceiverActive() {
		return truitonDevicePolicyManager
				.isAdminActive(truitonDevicePolicyAdmin);
	}

	public static class MyDevicePolicyReceiver extends DeviceAdminReceiver {

		@Override
		public void onDisabled(Context context, Intent intent) {
			Toast.makeText(context, "Truiton's Device Admin Disabled",
					Toast.LENGTH_SHORT).show();
		}

		@Override
		public void onEnabled(Context context, Intent intent) {
			Toast.makeText(context, "Truiton's Device Admin is now enabled",
					Toast.LENGTH_SHORT).show();
		}

		@Override
		public CharSequence onDisableRequested(Context context, Intent intent) {
			CharSequence disableRequestedSeq = "Requesting to disable Device Admin";
			return disableRequestedSeq;
		}

		@TargetApi(Build.VERSION_CODES.HONEYCOMB)
		@Override
		public void onPasswordChanged(Context context, Intent intent) {
			Toast.makeText(context, "Device password is now changed",
					Toast.LENGTH_SHORT).show();
			DevicePolicyManager localDPM = (DevicePolicyManager) context
					.getSystemService(Context.DEVICE_POLICY_SERVICE);
			ComponentName localComponent = new ComponentName(context,
					MyDevicePolicyReceiver.class);
			localDPM.setPasswordExpirationTimeout(localComponent, 0L);
		}

		@TargetApi(Build.VERSION_CODES.HONEYCOMB)
		@Override
		public void onPasswordExpiring(Context context, Intent intent) {
			// This would require API 11 an above
			Toast.makeText(
					context,
					"Truiton's Device password is going to expire, please change to a new password",
					Toast.LENGTH_LONG).show();

			DevicePolicyManager localDPM = (DevicePolicyManager) context
					.getSystemService(Context.DEVICE_POLICY_SERVICE);
			ComponentName localComponent = new ComponentName(context,
					MyDevicePolicyReceiver.class);
			long expr = localDPM.getPasswordExpiration(localComponent);
			long delta = expr - System.currentTimeMillis();
			boolean expired = delta &lt; 0L;
			if (expired) {
				localDPM.setPasswordExpirationTimeout(localComponent, 10000L);
				Intent passwordChangeIntent = new Intent(
						DevicePolicyManager.ACTION_SET_NEW_PASSWORD);
				passwordChangeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				context.startActivity(passwordChangeIntent);
			}
		}

		@Override
		public void onPasswordFailed(Context context, Intent intent) {
			Toast.makeText(context, "Password failed", Toast.LENGTH_SHORT)
					.show();
		}

		@Override
		public void onPasswordSucceeded(Context context, Intent intent) {
			Toast.makeText(context, "Access Granted", Toast.LENGTH_SHORT)
					.show();
		}

		@Override
		public void onReceive(Context context, Intent intent) {
			Log.i(LOG_TAG,
					"MyDevicePolicyReciever Received: " + intent.getAction());
			super.onReceive(context, intent);
		}
	}
}</pre>



<p class="wp-block-paragraph">Here in this class I have implemented Android DevicePolicyManager by a check box, on tap of check-box user is prompted to accept the device policies:</p>



<ul data-carousel-extra='{&quot;blog_id&quot;:1,&quot;permalink&quot;:&quot;https://www.truiton.com/2014/01/android-devicepolicymanager-example/&quot;}'  class="wp-block-gallery columns-3 is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex"><li class="blocks-gallery-item"><figure><img data-recalc-dims="1" loading="lazy" decoding="async" width="426" height="756" data-attachment-id="564" data-permalink="https://www.truiton.com/2014/01/android-devicepolicymanager-example/devicepolicymanager2/" data-orig-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/DevicePolicyManager2.png?fit=426%2C756&amp;ssl=1" data-orig-size="426,756" data-comments-opened="1" data-image-title="DevicePolicyManager2" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/DevicePolicyManager2.png?fit=426%2C756&amp;ssl=1" src="https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/DevicePolicyManager2.png?resize=426%2C756&#038;ssl=1" alt="Android DevicePolicyManager" data-id="564" class="wp-image-564" srcset="https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/DevicePolicyManager2.png?w=426&amp;ssl=1 426w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/DevicePolicyManager2.png?resize=169%2C300&amp;ssl=1 169w" sizes="auto, (max-width: 426px) 100vw, 426px" /></figure></li><li class="blocks-gallery-item"><figure><img data-recalc-dims="1" loading="lazy" decoding="async" width="425" height="757" data-attachment-id="565" data-permalink="https://www.truiton.com/2014/01/android-devicepolicymanager-example/devicepolicymanager3/" data-orig-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/DevicePolicyManager3.png?fit=425%2C757&amp;ssl=1" data-orig-size="425,757" data-comments-opened="1" data-image-title="DevicePolicyManager3" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/DevicePolicyManager3.png?fit=425%2C757&amp;ssl=1" src="https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/DevicePolicyManager3.png?resize=425%2C757&#038;ssl=1" alt="Android DevicePolicyManager" data-id="565" class="wp-image-565" srcset="https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/DevicePolicyManager3.png?w=425&amp;ssl=1 425w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/DevicePolicyManager3.png?resize=168%2C300&amp;ssl=1 168w" sizes="auto, (max-width: 425px) 100vw, 425px" /></figure></li><li class="blocks-gallery-item"><figure><img data-recalc-dims="1" loading="lazy" decoding="async" width="426" height="755" data-attachment-id="559" data-permalink="https://www.truiton.com/2014/01/android-devicepolicymanager-example/devicepolicymanager4/" data-orig-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/DevicePolicyManager4.png?fit=426%2C755&amp;ssl=1" data-orig-size="426,755" data-comments-opened="1" data-image-title="DevicePolicyManager4" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/DevicePolicyManager4.png?fit=426%2C755&amp;ssl=1" src="https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/DevicePolicyManager4.png?resize=426%2C755&#038;ssl=1" alt="Android DevicePolicyManager" data-id="559" class="wp-image-559" srcset="https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/DevicePolicyManager4.png?w=426&amp;ssl=1 426w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/DevicePolicyManager4.png?resize=169%2C300&amp;ssl=1 169w" sizes="auto, (max-width: 426px) 100vw, 426px" /></figure></li></ul>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">After user accepts the policies it is verified that is the active password sufficient by <em>DevicePolicyManager.isActivePasswordSufficient()</em> method, if it is then screen is locked by <em>DevicePolicyManager.lockNow()</em> method. Else user is taken to screen where he could set the password according to the device policy manager. Another great feature of Android DevicePolicyManager is that we can also set the maximum time in which device screen should lock by <em>DevicePolicyManager.setMaximumTimeToLock()</em> method. And if the amount of failed attempts cross the limit the device can also be wiped out:</p>



<ul data-carousel-extra='{&quot;blog_id&quot;:1,&quot;permalink&quot;:&quot;https://www.truiton.com/2014/01/android-devicepolicymanager-example/&quot;}'  class="wp-block-gallery columns-3 is-cropped wp-block-gallery-2 is-layout-flex wp-block-gallery-is-layout-flex"><li class="blocks-gallery-item"><figure><img data-recalc-dims="1" loading="lazy" decoding="async" width="426" height="758" data-attachment-id="560" data-permalink="https://www.truiton.com/2014/01/android-devicepolicymanager-example/devicepolicymanager5/" data-orig-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/DevicePolicyManager5.png?fit=426%2C758&amp;ssl=1" data-orig-size="426,758" data-comments-opened="1" data-image-title="DevicePolicyManager5" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/DevicePolicyManager5.png?fit=426%2C758&amp;ssl=1" src="https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/DevicePolicyManager5.png?resize=426%2C758&#038;ssl=1" alt="Android DevicePolicyManager5" data-id="560" class="wp-image-560" srcset="https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/DevicePolicyManager5.png?w=426&amp;ssl=1 426w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/DevicePolicyManager5.png?resize=168%2C300&amp;ssl=1 168w" sizes="auto, (max-width: 426px) 100vw, 426px" /></figure></li><li class="blocks-gallery-item"><figure><img data-recalc-dims="1" loading="lazy" decoding="async" width="425" height="757" data-attachment-id="561" data-permalink="https://www.truiton.com/2014/01/android-devicepolicymanager-example/devicepolicymanager6/" data-orig-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/DevicePolicyManager6.png?fit=425%2C757&amp;ssl=1" data-orig-size="425,757" data-comments-opened="1" data-image-title="DevicePolicyManager6" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/DevicePolicyManager6.png?fit=425%2C757&amp;ssl=1" src="https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/DevicePolicyManager6.png?resize=425%2C757&#038;ssl=1" alt="Android DevicePolicyManager6" data-id="561" class="wp-image-561" srcset="https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/DevicePolicyManager6.png?w=425&amp;ssl=1 425w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/DevicePolicyManager6.png?resize=168%2C300&amp;ssl=1 168w" sizes="auto, (max-width: 425px) 100vw, 425px" /></figure></li><li class="blocks-gallery-item"><figure><img data-recalc-dims="1" loading="lazy" decoding="async" width="426" height="757" data-attachment-id="562" data-permalink="https://www.truiton.com/2014/01/android-devicepolicymanager-example/devicepolicymanager7/" data-orig-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/DevicePolicyManager7.png?fit=426%2C757&amp;ssl=1" data-orig-size="426,757" data-comments-opened="1" data-image-title="DevicePolicyManager7" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/DevicePolicyManager7.png?fit=426%2C757&amp;ssl=1" src="https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/DevicePolicyManager7.png?resize=426%2C757&#038;ssl=1" alt="Android DevicePolicyManager" data-id="562" class="wp-image-562" srcset="https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/DevicePolicyManager7.png?w=426&amp;ssl=1 426w, https://i0.wp.com/www.truiton.com/wp-content/uploads/2014/01/DevicePolicyManager7.png?resize=168%2C300&amp;ssl=1 168w" sizes="auto, (max-width: 426px) 100vw, 426px" /></figure></li></ul>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">To uninstall any android device admin you need to first deactivate it, which would result in a callback to <em>DeviceAdminReceiver.onDisabled()</em> method where you can write the code to do something like erase some secure data or a complete wipe-out. With this I would like to conclude this tutorial by saying that there may be a case where your device would be having more than one active device policy managers, in that case the more strict DevicePolicyManager would be enforced. If you would like to know which Android DevicePolicyManager is active please read my next tutorial on <a title="Android Device Administrator Example" href="http://www.truiton.com/2014/01/android-device-administrator-example/" target="_blank" rel="noopener noreferrer">active device administrators</a>. If you like this tutorial please share it with your friends on Google+, Facebook and also like our Facebook page, to get our updates.</p>
<div class="saboxplugin-wrap" itemtype="http://schema.org/Person" itemscope itemprop="author"><div class="saboxplugin-tab"><div class="saboxplugin-gravatar"><img alt='Mohit Gupt' src='https://secure.gravatar.com/avatar/a816092ad56645d2635ccfceb9f7e9d44821c19dec126cb394c882ba574eaa04?s=100&#038;d=mm&#038;r=g' srcset='https://secure.gravatar.com/avatar/a816092ad56645d2635ccfceb9f7e9d44821c19dec126cb394c882ba574eaa04?s=200&#038;d=mm&#038;r=g 2x' class='avatar avatar-100 photo' height='100' width='100' itemprop="image"/></div><div class="saboxplugin-authorname"><a href="https://www.truiton.com/author/mohitgupt/" class="vcard author" rel="author"><span class="fn">Mohit Gupt</span></a></div><div class="saboxplugin-desc"><div itemprop="description"><p>Born in New Delhi, India. A software engineer by profession, an android enthusiast and mobile development evangelist. My motive here is to create a group of skilled engineers, who can build better software. Reason being programming is my passion, and also it feels good to make a device do something you want. Professionally I have worked with many software engineering and product development firms. As of now too, I am employed as a senior engineer in a leading tech company. In total I may have worked on more than 20 projects professionally, but whenever I get spare time I share my thoughts here at Truiton.</p>
</div></div><div class="saboxplugin-web "><a href="http://www.truiton.com" target="_self" >www.truiton.com</a></div><div class="clearfix"></div><div class="saboxplugin-socials "><a title="Wordpress" target="_blank" href="https://www.truiton.com/author/mohitgupt/" rel="nofollow noopener" class="saboxplugin-icon-grey"><svg aria-hidden="true" class="sab-wordpress" role="img" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 512 512"><path fill="currentColor" d="M61.7 169.4l101.5 278C92.2 413 43.3 340.2 43.3 256c0-30.9 6.6-60.1 18.4-86.6zm337.9 75.9c0-26.3-9.4-44.5-17.5-58.7-10.8-17.5-20.9-32.4-20.9-49.9 0-19.6 14.8-37.8 35.7-37.8.9 0 1.8.1 2.8.2-37.9-34.7-88.3-55.9-143.7-55.9-74.3 0-139.7 38.1-177.8 95.9 5 .2 9.7.3 13.7.3 22.2 0 56.7-2.7 56.7-2.7 11.5-.7 12.8 16.2 1.4 17.5 0 0-11.5 1.3-24.3 2l77.5 230.4L249.8 247l-33.1-90.8c-11.5-.7-22.3-2-22.3-2-11.5-.7-10.1-18.2 1.3-17.5 0 0 35.1 2.7 56 2.7 22.2 0 56.7-2.7 56.7-2.7 11.5-.7 12.8 16.2 1.4 17.5 0 0-11.5 1.3-24.3 2l76.9 228.7 21.2-70.9c9-29.4 16-50.5 16-68.7zm-139.9 29.3l-63.8 185.5c19.1 5.6 39.2 8.7 60.1 8.7 24.8 0 48.5-4.3 70.6-12.1-.6-.9-1.1-1.9-1.5-2.9l-65.4-179.2zm183-120.7c.9 6.8 1.4 14 1.4 21.9 0 21.6-4 45.8-16.2 76.2l-65 187.9C426.2 403 468.7 334.5 468.7 256c0-37-9.4-71.8-26-102.1zM504 256c0 136.8-111.3 248-248 248C119.2 504 8 392.7 8 256 8 119.2 119.2 8 256 8c136.7 0 248 111.2 248 248zm-11.4 0c0-130.5-106.2-236.6-236.6-236.6C125.5 19.4 19.4 125.5 19.4 256S125.6 492.6 256 492.6c130.5 0 236.6-106.1 236.6-236.6z"></path></svg></span></a><a title="Twitter" target="_blank" href="http://twitter.com/mohitgupt" rel="nofollow noopener" class="saboxplugin-icon-grey"><svg aria-hidden="true" class="sab-twitter" role="img" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 30 30"><path d="M26.37,26l-8.795-12.822l0.015,0.012L25.52,4h-2.65l-6.46,7.48L11.28,4H4.33l8.211,11.971L12.54,15.97L3.88,26h2.65 l7.182-8.322L19.42,26H26.37z M10.23,6l12.34,18h-2.1L8.12,6H10.23z" /></svg></span></a><a title="Facebook" target="_blank" href="https://www.facebook.com/Mr.Mohit.Gupt" rel="nofollow noopener" class="saboxplugin-icon-grey"><svg aria-hidden="true" class="sab-facebook" role="img" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 264 512"><path fill="currentColor" d="M76.7 512V283H0v-91h76.7v-71.7C76.7 42.4 124.3 0 193.8 0c33.3 0 61.9 2.5 70.2 3.6V85h-48.2c-37.8 0-45.1 18-45.1 44.3V192H256l-11.7 91h-73.6v229"></path></svg></span></a></div></div></div><p>The post <a href="https://www.truiton.com/2014/01/android-devicepolicymanager-example/">Android DevicePolicyManager Example</a> appeared first on <a href="https://www.truiton.com">Truiton</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.truiton.com/2014/01/android-devicepolicymanager-example/feed/</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">556</post-id>	</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Minified using Disk

Served from: www.truiton.com @ 2026-07-07 22:18:06 by W3 Total Cache
-->