简体   繁体   English

如何在应用程序内执行ADB命令

[英]How to execute ADB commands within an app

I've got a partially rooted android device. 我有一个部分植根的android设备。 By partial root, I mean that I can only run root commands through ADB. 我说的是部分root用户,我只能通过ADB运行root命令。 I've figured out how to run these commands locally from within a terminal emulator on the device itself. 我已经弄清楚了如何从设备本身的终端仿真器中本地运行这些命令。 My question is, how would I go about writing the code for an Android application that executes an ADB command (or multiple commands) from a button press? 我的问题是,如何为按下按钮执行ADB命令(或多个命令)的Android应用程序编写代码? I can't find anything that explains how to run direct ADB commands through an app interface. 我找不到任何能解释如何通过应用程序界面运行直接ADB命令的内容。 Just to clarify, anything that involves "su" will not work on this device. 为了澄清起见,涉及“ su”的所有内容在此设备上均不起作用。 It only accepts ADB input for root access. 接受ADB输入以进行根访问。

Not sure if it works on Android, but have you tried this: 不知道它是否可以在Android上运行,但是您尝试过以下方法:

Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("adb do something as root");

If you provide more info about what exactly you need to use adb for in this manner, there may be a better workaround. 如果您提供有关以这种方式确切需要使用adb的详细信息,则可能会有更好的解决方法。 It is very unlikely you actually need this behavior in app, and I believe it would be generally frowned upon. 您实际上不太可能在应用程序中需要此行为,并且我相信它通常会被皱眉。 It sounds like you want your app to have root, but this seems like a very unportable and unnecessary approach. 听起来您想让您的应用程序具有根目录,但这似乎是一种非常不可移植且不必要的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM