how to turn on / turn off developer mode in Android from app?

1.9k views Asked by At

I want to create an app to turn on/turn off Android developer mode. This will be on a rooted device. What api's do need to call?

2

There are 2 answers

0
Hannoun Yassir On

I don't think it is possible. Since it is part of the Settings.Secure.

Secure system settings, containing system preferences that applications can read but are not allowed to write. These are for preferences that the user must explicitly modify through the system UI or specialized APIs for those values, not modified directly by applications.

0
Karanveer Singh On

I know i am answering it very late but i will surely help other who are searching on this.

To enable developer options programatically :

Settings.Global.putString(this.getContentResolver(), Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, "1");

To disable :

Settings.Global.putString(this.getContentResolver(), Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, "0");

But to access this Settings.Global... , it requires a permission

android.permission.WRITE_SECURE_SETTINGS

But normally , This permission is only granted to system app

You can also grant this permission to user app using ADB

Since you said your app would be running on a rooted deice , so have access to the shell , so you can grant this permission to your app by running the below shell command

pm grant <your.package.name> android.permission.WRITE_SECURE_SETTINGS