展望启用和禁用(切换)亚洲开发银行或USB调试使用命令行或应用程序 [英] Looking to enable and disable (toggle) ADB or USB debugging using command line or in app
问题描述
我想要做的是使亚洲开发银行(USB调试),只有当我的应用程序正在运行,并禁用它,当我的应用程序是没有的。我有充分的机会来了电话,它根植,苏可,等等。但我不能找到一种方法,做切换。
What I'm trying to do is enable adb (USB debugging) only when my application is running and disabling it when my application is not. I have full access to the phone and it is rooted, su available, etc.. but I cannot find a way to do the toggling.
任何建议?
我试过到目前为止:
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();
然而,这将导致手机瞬间进入一个重新启动循环。
This however causes the phone to enter a reboot loop instantaneously.
推荐答案
在code,它的工作原理很简单:
The code that works is easy:
Settings.Secure.putInt(getContentResolver(),Settings.Secure.ADB_ENABLED, 0); // 0 to disable, 1 to enable
修改/更新: 感谢@MohanT以下更新:
Edit/Update: Thanks to @MohanT for the following update:
Settings.Global.putInt(getContentResolver(),Settings.Global.ADB_ENABLED, 0); // 0 to disable, 1 to enable
然而,该应用需要是一个系统的应用程序,以便能够使用它。为了摆脱不必签署它,建立一个自定义ROM等。我做了以下得到它是一个系统的应用程序。
However, the app needs to be a system app to be able to use this. To get out of having to sign it, build a custom rom, etc.. I did the following to get it to be a system app.
首先,我安装了它经常使用Eclipse,那么亚行的shell:
First, I installed it regularly using eclipse, then adb shell:
> su
# mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system
# cat /data/app/filename.apk > /system/app/filename.apk
# mount -o remount,ro -t yaffs2 /dev/block/mtdblock3 /system
# reboot
这篇关于展望启用和禁用(切换)亚洲开发银行或USB调试使用命令行或应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!