0

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?

Rookie
  • 735
  • 5
  • 11
  • 30
  • also see: https://stackoverflow.com/questions/3458275/enable-usb-debugging-under-settings-applications-development-programmatically and https://stackoverflow.com/questions/18782546/can-we-programatically-enable-disable-usb-debugging-on-android-devices?noredirect=1&lq=1 – albert c braun Sep 18 '17 at 22:04

2 Answers2

2

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

0

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.

Hannoun Yassir
  • 20,583
  • 23
  • 77
  • 112