【发布时间】:2021-11-14 06:57:43
【问题描述】:
这是我的代码 基本上在手机中使用 adb 来卸载应用程序,但它目前无法正常工作,任何人都可以帮助我
Process pro;
StringBuilder output = new StringBuilder();
try {
pro = Runtime.getRuntime().exec(new String[]{"pm uninstall –k ––user 0
com.google.android.gm"});
BufferedReader reader = new BufferedReader(
new InputStreamReader(pro.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
output.append(line).append(" ");
pro.waitFor();
}
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
String response = output.toString();
System.out.println(response);
Log.d("log", response);
这是我遇到的错误
W/System.err: java.io.IOException: Cannot run program "pm uninstall –k ––user 0
com.google.android.gm": error=13, Permission denied
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1050)
W/System.err: at java.lang.Runtime.exec(Runtime.java:698)
at java.lang.Runtime.exec(Runtime.java:563)
at com.example.adb.MainActivity.onCreate(MainActivity.java:23)
谁能解决这个问题。
【问题讨论】:
-
Runtime.getRuntime().exec() 中的 arg 正在使用的设备的 adb shell 上运行。据我所知。
标签: java android adb uninstallation