4

我如何在android中以编程方式通过tcp启动adb服务器...具有root权限我发现这个命令可以...

setprop service.adb.tcp.port 5555

有没有办法在android中以编程方式执行这个

4

1 回答 1

0

您需要 root 访问权限才能执行此操作。否则这将是一个巨大的安全问题。您可以使用 libsuperuser 之类的库来运行 root 命令。

使用 libsuperuser 的示例:

String[] commands = { "setprop service.adb.tcp.port 5555", "stop adbd", "start adbd" };
Shell.SU.run(commands);
// Get the WiFi IP address
WifiManager mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
int ip = mWifiManager.getConnectionInfo().getIpAddress();
String wifiIp = (ip & 0xFF) + "." + ((ip >> 8) & 0xFF) + "." + ((ip >> 16) & 0xFF) + "."
        + ((ip >> 24) & 0xFF);
// Tell the user what the next step is.
Toast.makeText(context,
    String.format("Run 'adb connect %s:5555' in terminal/command-prompt", wifiIp),
    Toast.LENGTH_LONG).show();
于 2014-12-11T07:20:36.627 回答