[Android] Mobile defender Device Management rights lock screen

Source: Internet
Author: User
Tags myadmin

Device administrator Devices admin

Gets the devicepolicymanager object, via getsystemservice (device_policy_manager), device policy manager

Call the Devicepolicymanager object's locknow () method, lock, and report a security exception at this time

Create a new class MyAdmin inherit the system deviceadminreceiver, this is the broadcast receiver

Manifest file to register

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 and create a new device_admin_sample.xml file

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

There will be an error at this

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

Turn on administrator privileges

Get Intent object,new Intent (devicepolicymanager.action_add_device_admin)

Call the Intent object PutExtra (), Pass the 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 explanatory data, persuade the user to open, parameters:

Devicepolicymanager.extra_add_explanation, Text

Call startactivity ()

Call the isadminactive () method of the Devicepolicymanager object to determine whether there are administrator permissions, parameters: ComponentName Object

Call the ResetPassword () method of the devicepolicymanager object , reset the password, parameter:password,0 , put Password set to "to cancel the password

Call the Wipedata () method of the devicepolicymanager Object , clear the data, parameters: Clear SD card Deviceplocymanager.wipe_exteranl_storge

If it's 0, it's factory reset.

Uninstalling software

It's not going to get unloaded on this outfit.

Call the removeactiveadmin () method of the Devicepolicymanager object , clear administrator permissions, parameters:componentname Component Name object, get componentname object,new out, Parameters: Context,Myadmin.class

Get Intent Object

Call the setaction () method of the Intent Object , set the action, parameter:Android.intent.action.VIEW

Call the Intent object's addcategory () Add type, parameter: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-adminxmlns: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>

 PackageCom.tsh.mylockscreen;Importandroid.app.Activity;ImportAndroid.app.admin.DevicePolicyManager;ImportAndroid.content.ComponentName;Importandroid.content.Intent;ImportAndroid.net.Uri;ImportAndroid.os.Bundle;ImportAndroid.view.View;ImportAndroid.widget.Toast; Public classMainactivityextendsActivity {PrivateDevicepolicymanager DPM;    ComponentName who; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); DPM=(Devicepolicymanager) Getsystemservice (Device_policy_service); W.H.O.=NewComponentName ( This, MyAdmin.class); }    //One button lock screen     Public voidLockscreen (View v) {if(Dpm.isadminactive (WHO)) {Dpm.locknow (); Dpm.resetpassword ("123", 0); } Else{Intent Intent=NewIntent (devicepolicymanager.action_add_device_admin);            Intent.putextra (Devicepolicymanager.extra_device_admin, WHO); Intent.putextra (Devicepolicymanager.extra_add_explanation,"Turn it on.");            StartActivity (Intent); Toast.maketext ( This, "No Device Management rights", 1). Show (); }    }    //One-click Uninstall     Public voidUninstall (View v) {dpm.removeactiveadmin (WHO); Intent Intent=NewIntent ();        Intent.setaction (Intent.action_delete); Intent.addcategory ("Android.intent.category.DEFAULT"); Intent.setdata (Uri.parse ("Package:" +getpackagename ()));    StartActivity (Intent); }}

[Android] Mobile defender Device Management rights lock screen

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.