Android Apidemos Sample Resolution App->device Admin

Source: Internet
Author: User
Tags final

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.