An application with administrator privileges can use the device administration API. This API offers the ability to erase a device.
Using this, he does not need superuser permissions, he only needs the administrator rights of the device .
To summarize the use of the device administration API :
- You need a resource file that announces the policies your application needs.
<device-admin xmlns:android="http://schemas.android.com/apk/res/android"> <uses-policies> <wipe-data /> </uses-policies> </device-admin>
You need to implement DeviceAdminReceiver in order to respond to various administration events in which your application is interested (an empty implementation may be sufficient if you are only interested in a wipe device) (more about how to configure this receiver: here )
You need permission BIND_DEVICE_ADMIN
At some point (possibly at startup), your application should call ACTION_ADD_DEVICE_ADMIN to ask the user to provide “Device Control Rights” to your application. (once these rights are granted, there is no reason to ask them again. The user always has the opportunity to revoke these rights in the Settings application).
When your installation is correct (and if the user provides device administrator privileges for your application), you can call DevicePolicyManager:
DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE); devicePolicyManager.wipeData(0);
Please note that an application with device administrator rights cannot be disabled. The user must manually remove these rights (using the Settings application) before he can install it.
ben75 source share