Android requires super user for deleting, modifying or reading anything in the root directory except system which is read only.
However, I have noticed that even without a rooted device, some applications are able to take advantage of these processes. For example, Norton is able to do device wipes on non-rooted phones. Is there a way to grant my application similar access?
Go to your phone's settings and then click on “Security.” You'll see “Device Administration” as a security category. Click on it to see a list of apps that have been given administrator privileges. Click the app you want to remove and confirm that you want to deactivate administrator privileges.
The device admin app enforces the desired policies. Here's how it works: A system administrator writes a device admin app that enforces remote/local device security policies. These policies could be hard-coded into the app, or the app could dynamically fetch policies from a third-party server.
An application with Administrator Rights can use the Device Administration API. This API offers the ability to wipe the device.
Using this, it doesn't need any super-user permissions, it only needs device administrator rights.
To summarize how to use the Device Administration API:
<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
<uses-policies>
<wipe-data />
</uses-policies>
</device-admin>
You need to implement a DeviceAdminReceiver to react to various administration event your app is interested in. (an empty implementation can be enough if you are only interested in wipe-device) (more details on how to setup this receiver: here)
You need the BIND_DEVICE_ADMIN permission
At some point (probably at start up) your app must trigger ACTION_ADD_DEVICE_ADMIN to ask to the user to grant "Device Administration Rights" to your app. (once those rights are granted, there is no reason to ask them again. The user always have the ability to un-grant those rights from the Settings app)
When your setup is correct (and if the user grant Device Admin rights to your app), you can invoke the DevicePolicyManager:
DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
devicePolicyManager.wipeData(0);
Note that an app with device administrator rights cannot be un-installed. The user needs to manually remove those rights (with the Settings app) before being able to un-install it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With