Mobile Security defender------Mobile anti-theft page destruction Data & Remote lock screen

Source: Internet
Author: User
Tags myadmin

The ability to destroy data and remote lock screens is achieved by obtaining device Administrator privileges

1. First create a class that inherits Deviceadminreceiver. Look at the class name and you'll guess it's probably a broadcastreceiver. Make sure this is a broadcast subclass by looking at the source code. So you have to register on the manifest file.
View the official Android API:

<receiver android:name=". MyAdmin "android:label=" @string/description "android:description=" @string/ Label "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>

Where: description is descriptive information; label is descriptive information label;
Also create an XML directory under the resource directory to create the 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>

2. In the Java file:

    • To turn on Device management policy permissions:

      • Create a intent
        Intent Intent = new Intent (devicepolicymanager.action_add_device_admin);
      • Select the name of the control you want to manipulate
        ComponentName mdeviceadminsimple = new ComponentName (mainactivity.this,myadmin.class);
      • Activating Device Management policies
        Intent.putextra (devicepolicymanager.extra_device_admin,mdeviceadminsample);
      • Add a Description language
        Intent.putextra (devicepolicymanager.extra_add_explanation, "open permission, one click Lock screen, save home button!");

      • Complete, startactivity;
        StartActivity (Intent);

    • Create a Device management policy
      Private Devicepolicymanager DPM;
      DPM = Getsystemservice (Device_policy_service);
      One-click Lock screen, set the password
      Dpm.locknow ();
      Dpm.setpassword (password value, additional added value set to 0);
      Clear Data
      Dpm.wipedata (0)//restore factory settings
      Dpm.wipedate (Devicepolicymanager.wipe_external_storage); Format SD Card

User cannot uninstall the current app because of device management mechanism (good cock appearance ~ ~)

We need to provide the uninstall function separately:

    //取消设备管理员权限    manager.removeActiveAdmin(mDeviceAdminSimple);    //卸载    Intent intent = new Intent();    intent.setAction("android.intent.action.VIEW");    intent.addCategory("android.intent.category.DEFAULT");    intent.setData(Uri.parse("package:" + getPackageName()));    startActivity(intent);

Copyright notice: Just out of the original content of the pot, I hope you have help ~

Mobile Security defender------Mobile anti-theft page destruction Data & Remote lock screen

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.