How to access device settings programmatically?

前端 未结 6 1676
礼貌的吻别
礼貌的吻别 2020-12-05 05:59

Is there any way to access device settings programmatically?

For Example: Settings > Developer Options > USB debugging > True/False

Thanks in advance.

<
6条回答
  •  萌比男神i
    2020-12-05 06:12

    If you app is System app then you Simply do this to enable/disable USB Debugging

    Settings.Secure.putInt(getActivity().getContentResolver(),Settings.Secure.ADB_ENABLED, 1);

    You also need root access to do this. I have rooted device and I just simply execute SU to enable/disable Usb Debugging.

    Process proc = Runtime.getRuntime().exec(new String [] { "su", "-c", "setprop", "persist.service.adb.enable", "0"});

    proc.waitFor();

    Process proc2 = Runtime.getRuntime().exec(new String [] { "su", "-c", "stop", "adbd"});

    proc2.waitFor();

    Good thing is you don't need to place your application in (/system/priv-app/) Your simple app i.e. (/data/app) can do this.

提交回复
热议问题