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