The Device Admin example describes class Deviceadminreceiver,devicepolicymanager and Activitymanager.
Class Devicepolicymanager A number of strategies for managing the definition of an Android device, mainly referring to the length of the password definition, whether the password needs to be in uppercase letters, the specification required to set passwords for lowercase letters, locking devices, or clearing all user data, This class generally needs to be used in conjunction with Deviceadminreceiver. Deviceadminreceiver is derived from broadcastreceiver and can accept intent events from the Android operating system: Passwords expire, passwords are updated, and so on.
When it publish in Androidmanifest.xml as a broadcastreceiver definition, you must deal with Android.app.action.DEVICE_ADMIN_ Enabled and set Android.permission.BIND_DEVICE_ADMIN permissions:
<receiver android:name= ". App. Deviceadminsample "
Android:label= "@string/sample_device_admin"
android:description= "@string/sample_device_admin_description"
android:permission= "Android.permission.BIND_DEVICE_ADMIN" >
<meta-data android:name= "Android.app.device_admin"
Android:resource= "@xml/device_admin_sample"/>
<intent-filter>
<action android:name= "Android.app.action.DEVICE_ADMIN_ENABLED"/>
</intent-filter>
</receiver>
Use Devicepolicymanager to set the policy of the password definition
void
updatepolicies () {
Sharedpreferences prefs = getsamplepreferences (this);
Final int pwquality = Prefs.getint (pref_password_quality,
devicepolicymanager.password_quality_unspecified);
Final int pwlength = prefs.getint (pref_password_length, 0);
Final int maxfailedpw = prefs.getint (PREF_MAX_FAILED_PW, 0);
Boolean active = Mdpm.isadminactive (mdeviceadminsample);
if (active) {
mdpm.setpasswordquality (mdeviceadminsample, pwquality);
Mdpm.setpasswordminimumlength (Mdeviceadminsample, pwlength);
Mdpm.setmaximumfailedpasswordsforwipe (Mdeviceadminsample, MAXFAILEDPW);
}
Locking Device methods:
Mdpm.locknow ();
Erase all user data (equivalent to master Reset)
Mdpm.wipedata (0);
The Activitymanager class is typically used to get information about all the running activity in the Android system, somewhat like a task Manager in Windows. Can obtain Memory, Process, service and other information. In the example, a very funny method is used: Isuseramonkey, to determine whether the current device user is a monkey:-). Really don't know if to judge, I think if this is a knock on the keyboard will make this function return "true." The result is not:).
In general, these classes and methods are rarely used in general applications, and some impressions are available.