Run Adb Shell Commands From Java Code On Different Platforms
I am using Mac to run Java program which contains some commands to execute on a remote Android device. When I execute my program on a Windows machine it gives proper output but whe
Solution 1:
Better use ProcessBuilder
instead. But if you insist on using Runtime.getRuntime().exec()
- use .exec(String[] cmdarray)
instead of your current .exec(String command)
:
private static final String DUMPSYSCOMMAND = "dumpsys package com.PACKAGENAME.service | grep versionName";
String versionString = runADBCommand({"adb", "-s", deviceIP, "shell", DUMPSYSCOMMAND});
...
public String runADBCommand(String[] adbCommand) throws IOException {
...
// do not forget to remove / modify this println - it expect a string
// System.out.println("adbCommand = " + adbCommand);
Post a Comment for "Run Adb Shell Commands From Java Code On Different Platforms"