ADB commands in code

2019-05-11 15:52发布

问题:

Is there a way to run adb commands like

adb get-state

in the code I write in eclipse

For e.g.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    testADB();
}

and in testADB() run some adb commands?

回答1:

Adithya , I believe you are trying to drop adb commands programmatically.Check this link.



回答2:

Not literally, due to permissions and the security model. The usb adb daemon on a consumer phone runs with slightly higher privileges than ordinary applications, so accepting commands from them would be a security hole.

However as others have pointed out, there may be alternative means to obtain some kinds of data.



回答3:

You can probably use some of the classes in ddmlib.jar for that.



标签: android adb