4

How can i start adb server over tcp programmatically in android...with root permission i found that this command will do...

setprop service.adb.tcp.port 5555

is there any way to execute this programmatically in android

1
  • have you tried use Runtime.exec("setprop service.adb.tcp.port 5555"); in android?
    – buptcoder
    Jun 7, 2013 at 9:36

1 Answer 1

0

You need root access to do this. It would be a huge security issue otherwise. You can use a library like libsuperuser to run root commands.

Example using 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();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.