1. Define special broadcast receivers, broadcast receivers of the system super administrator
public class MyDeviceAdminReceiver extends DeviceAdminReceiver{ @Override public void onReceive(Context context,Intent intent){ //TODO } }
2. In the file, register the broadcast receiver of the super administrator
<receiver android:name="" android:permission=".BIND_DEVICE_ADMIN"> <meta-data android:name=".device_admin" android:resource="@xml/device_admin_sample"/> <intent-filter> <action android:name=".DEVICE_ADMIN_ENABLED"/> </intent-filter> </receiver>
3. Create a policy declaration in res/xml
<device-admin xmlns:andro> <uses-policies> <force-lock/><!--Forced screen lock--> <wipe-data/><!--Clear data--> <reset-password/><!--Reset password--> ... </uses-policies>
Supplementary knowledge:Android obtains ROOT permissions through code
Getting Android's ROOT permissions is actually very simple. Just execute the command "su" under Runtime.
First, we need to check whether we already have root permissions, and the judgment code is as follows:
// Determine whether you have ROOT permissionspublic static boolean is_root(){ boolean res = false; try{ if ((!new File("/system/bin/su").exists()) && (!new File("/system/xbin/su").exists())){ res = false; } else { res = true; }; } catch (Exception e) { } return res; }
Then we execute the code to get root permissions
// Get ROOT permissionspublic void get_root(){ if (is_root()){ (mCtx, "Already have ROOT permission!", Toast.LENGTH_LONG).show(); } else{ try{ progress_dialog = (mCtx, "ROOT", "Getting ROOT permissions...", true, false); ().exec("su"); } catch (Exception e){ (mCtx, "An error occurred while obtaining ROOT permission!", Toast.LENGTH_LONG).show(); } } }
The above article on Android's acquisition of super administrator rights is all the content I have shared with you. I hope you can give you a reference and I hope you can support me more.