An analysis of Android mobile phone defender Device Management Permissions lock screen _android

Source: Internet
Author: User
Tags md5 encryption myadmin

Recommended reading:

An analysis of Android phone defender SIM card binding

An in-depth analysis of the Android phone defender MD5 encryption when saving passwords

Detailed Android Phone Guardian Settings Wizard page

An analysis of Android phone defender turn off automatic Updates

A brief analysis of Android phone defender custom control properties

An analysis of Android phone defender reading contacts

On the Android handset Guardian receives the short message instruction to carry on the corresponding operation

On the principle of mobile phone positioning of Android mobile phone Guardian

On the mobile phone of Android mobile phone to realize the location of SMS command acquisition

Device Administrator Device Admin

Gets the Devicepolicymanager object, through Getsystemservice (Device_policy_manager), device policy Manager

Call the Devicepolicymanager object's Locknow () method, lock, and then report a security exception

Create a new Class MyAdmin inheritance system Deviceadminreceiver, this is the broadcast receiver

Manifest file for registration

Add <receiver> node, set name

Set permissions android:permission= "Android.permission.BIND_DEVICE_ADMIN"

Add <meta-data> Meta Data node, set name Android:name= "Android.app.device_admin"

Set resource android:resource= "@xml/device_admin_sample"

Create a new XML folder in the Res directory, create a new Device_admin_sample.xml file

Add <intent-filter> node, add action, Android.app.action.DEVICE_ADMIN_ENABLED

There will be an error at this time

Open system settings, locate Device Manager, check device Administrator rights, activate device

Turn on administrator rights

Get Intent object, new Intent (Devicepolicymanager.action_add_device_admin)

Invokes the Intent object Putextra (), passing data, the component to be activated,

Parameters: Devicepolicymanager.extra_device_admin,componentname Component Name Object

Get ComponentName object, new out, Parameters: Context, Myadmin.class

Call the Intent Object Putextra (), pass the narration data, persuade the user to open, parameter:

Devicepolicymanager.extra_add_explanation, text

Call StartActivity ()

Call the Devicepolicymanager object's Isadminactive () method to determine whether there are administrator permissions, parameters: ComponentName objects

Call the Devicepolicymanager object's ResetPassword () method, reset the password, parameters: password,0, set the password to "" To cancel the password

Call the Devicepolicymanager object's Wipedata () method, clear data, Parameters: Clear SD card Deviceplocymanager.wipe_exteranl_storge

If it is 0, is to restore factory settings

Uninstall software

This one's not going to unload.

Call the Devicepolicymanager object's Removeactiveadmin () method, clear administrator permissions, Parameters: ComponentName Component Name object, Get ComponentName object, new out, parameter: context, Myadmin.class

Get Intent Object

Invokes the Setaction () method of the intent object, setting the action, parameters: Android.intent.action.VIEW

Call the Intent object's Addcategory () add type, Parameters: Android.intent.category.DEFAULT

Call the Intent object's SetData (), set the data,

Parameters: Uri object, get Uri object Uri.parse ("Package:" +getpackagename ())

Call StartActivity ()

Device_admin_sample.xml

<device-admin xmlns:android= "Http://schemas.android.com/apk/res/android" >
<uses-policies>
<limit-password/>
<watch-login/> <reset-password/> <force-lock/>
< Wipe-data/>
<expire-password/>
<encrypted-storage
/> <disable-camera/> </uses-policies>
</device-admin>

Package com.tsh.mylockscreen;

Import android.app.Activity;
Import Android.app.admin.DevicePolicyManager;
Import Android.content.ComponentName;
Import android.content.Intent;
Import Android.net.Uri;
Import Android.os.Bundle;
Import Android.view.View;
Import Android.widget.Toast;
public class Mainactivity extends activity {private Devicepolicymanager DPM;
ComponentName who; @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (
R.layout.activity_main);
DPM = (Devicepolicymanager) getsystemservice (Device_policy_service);
Who=new ComponentName (this, myadmin.class); }//One-key lock-screen public void Lockscreen (View v) {if (dpm.isadminactive) {dpm.locknow (); Dpm.resetpassword ("123", 0);} Els e {Intent Intent =new Intent (devicepolicymanager.action_add_device_admin); Intent.putextra (
Devicepolicymanager.extra_device_admin, WHO);
Intent.putextra (Devicepolicymanager.extra_add_explanation, "open it quickly");
StartActivity (Intent);
Toast.maketext (This, "No device admin rights", 1). Show (); }//AKey unload public void uninstall (View v) {dpm.removeactiveadmin (WHO);
Intent intent=new Intent ();
Intent.setaction (Intent.action_delete);
Intent.addcategory ("Android.intent.category.DEFAULT");
Intent.setdata (Uri.parse ("Package:" +getpackagename ()));
StartActivity (Intent); }
}

The above is a small set to introduce the Android mobile phone defender Device management rights of the relevant knowledge of the lock screen, I hope to help you!

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.