Android Project Device Manager

Source: Internet
Author: User

Device Manager is the ability to clear data, and lock screen and so on operations

Here we are going to intercept by SMS blocker (broadcast receiver) and then by SMS content,

Here's how it's done:

The first thing to do is to create a class to inherit Deviceadminreceiver

and register it in the manifest file.


<receiver
Android:name= ". Adminrecever "
android:description= "@string/sample_device_admin_description"
Android:label= "@string/sample_device_admin"
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>

Note that there is a reference to an XML file

Create an XML folder under the Res directory

Then the

<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>

Copy it in.

In the end, it can be manipulated in the activity.

 Packagecom.itheima52.admin;Importandroid.app.Activity;ImportAndroid.app.admin.DevicePolicyManager;ImportAndroid.content.ComponentName;ImportAndroid.content.Context;Importandroid.content.Intent;ImportAndroid.net.Uri;ImportAndroid.os.Bundle;ImportAndroid.view.View;ImportAndroid.widget.Toast; Public classMainactivityextendsActivity {PrivateDevicepolicymanager MDPM; Privatecomponentname mdeviceadminsample; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); MDPM= (Devicepolicymanager) getsystemservice (Context.device_policy_service);//Get device Policy ServiceMdeviceadminsample =NewComponentName ( This, Adminreceiver.class);//Device Management Components//Mdpm.locknow ();//Lock Screen now//finish ();    }    //Activate Device Manager, or manually in Device Manager, security, Settings     Public voidactiveadmin (view view) {Intent Intent=NewIntent (devicepolicymanager.action_add_device_admin);        Intent.putextra (Devicepolicymanager.extra_device_admin, mdeviceadminsample); Intent.putextra (Devicepolicymanager.extra_add_explanation,"Hahaha, we have a Super Device Manager, good nb!");    StartActivity (Intent); }    //One button lock screen     Public voidlockscreen (view view) {if(Mdpm.isadminactive (Mdeviceadminsample)) {//determine if Device Manager has been activatedMdpm.locknow ();//Lock Screen nowMdpm.resetpassword ("123456", 0); } Else{Toast.maketext ( This, "Device Manager must be activated first!", Toast.length_short). Show (); }    }     Public voidcleardata (view view) {if(Mdpm.isadminactive (Mdeviceadminsample)) {//determine if Device Manager has been activatedMdpm.wipedata (0);//Clear data, restore factory settings}Else{Toast.maketext ( This, "Device Manager must be activated first!", Toast.length_short). Show (); }    }     Public voidUnInstall (view view) {mdpm.removeactiveadmin (mdeviceadminsample);//Cancel Activation//Uninstalling the programIntent Intent =NewIntent (Intent.action_view);        Intent.addcategory (Intent.category_default); Intent.setdata (Uri.parse ("Package:" +getpackagename ()));    StartActivity (Intent); }}

Android Project Device Manager

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.