Enable USB debugging (under settings/applications/development) programmatically from within an app

后端 未结 5 1222
北海茫月
北海茫月 2020-12-11 03:23

Is it possible to enable USB debugging (under settings/applications/development) programmatically from within my app?

I was looking at Permission.WRITE_SETTING

5条回答
  •  抹茶落季
    2020-12-11 04:06

    You can enable adb programmatically by requesting WRITE_SECURE_SETTINGS in manifest and granting it over adb shell:

    adb shell pm grant your.package.name android.permission.WRITE_SECURE_SETTINGS
    

    Then you can enable adb on API 17 and above by calling:

    Settings.Global.putString(mContext.getContentResolver, Settings.Global.ADB_ENABLED,"1");
    

    For API 16 to API 3 call:

    Settings.Secure.putString(mContext.getContentResolver, Settings.Secure.ADB_ENABLED,"1");
    

    To disable adb replace "1" with "0" in commands

提交回复
热议问题