3

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?

Octavian Helm
  • 39,405
  • 19
  • 98
  • 102
Adithya
  • 2,923
  • 5
  • 33
  • 47

3 Answers3

3

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

100rabh
  • 6,156
  • 5
  • 27
  • 41
  • You cannot execute adb commands from android apps, but you can execute some commands that can also be (and more often are) executed via adb. – Chris Stratton Dec 07 '10 at 18:29
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.

Chris Stratton
  • 39,853
  • 6
  • 84
  • 117
0

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

mibollma
  • 14,959
  • 6
  • 52
  • 69
  • I went through the Jar and didn't find anything useful for my purpose.Actually i want to get memory related information like Heap and stack information allocated for the dalvik VM ? Plus i want to get memory allocation information for each application running on the android emulator. There are options like RAM size and Heap size which we can specify while launching an AVD ?? Can anyone elaborate on it ? – Adithya Dec 07 '10 at 13:49
  • The link i gave you is the Java API of adb. Maybe you should have a look at how ddms is implemented instead. – mibollma Dec 07 '10 at 13:55
  • can you point me to any link as to how ddms is imeplemented ? Thanks a lot ! – Adithya Dec 08 '10 at 09:45
  • This is the ddms source: http://android.git.kernel.org/?p=platform/sdk.git;a=tree;f=ddms/app/src/com/android/ddms;hb=HEAD – mibollma Dec 08 '10 at 20:24