Disable mobile network programmatically

后端 未结 3 995
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-29 17:16

I\'m developing an app in which user can enable/disable mobile network on button click. I googled regarding this, but I get the solution of Airplane mode only. In airplane m

3条回答
  •  旧巷少年郎
    2020-12-29 18:08

    If you have root-permission you can use this method to disable mobile network:

    try {
        Runtime.getRuntime().exec("su -c svc data disable");
    } catch (IOException e) {
        Log.d("Error", e.getMessage());
    }
    

    If you want to enable mobile network, just replace disable with enable.

提交回复
热议问题