I referred to this link - Use CreateProcess to execute ADB command. The approach used in the above link requires Windows.h file which is contained in windows SDk. Since i am executing Android Studio in Mac i will not be able to get the include file. I am not sure whether the above mentioned approach can be performed using Android Studio in Mac.
Asked
Active
Viewed 2,012 times
1 Answers
1
You can use system
or popen
methods to start an adb
process.

Kong Chun Ho
- 268
- 4
- 14
-
Thanks konh chun ho :) I tried to execute "su -c dumpsys meminfo package name". On executing this command the IOStream returned in null. I dont get any data. – andy Jul 13 '16 at 04:53
-
i thought you are running `adb`? Why you are running `su`? You can get the stdout when you are using `popen`. – Kong Chun Ho Jul 13 '16 at 08:29
-
I need to get the Heap size, heap alloc and heap free details for the given pid or package name... so i tried to to execute "dumpsys meminfo package_name" ---- this is producing an error: "Permission Denial: can't dump meminfo from from pid=21401, uid=10061" – andy Jul 13 '16 at 11:11
-
OK, i see what you are doing. Maybe the correct command to do is `su -c adb shell dumpsys meminfo package_name`? – Kong Chun Ho Jul 13 '16 at 13:00
-
already we are in adb shell right? do we need adb shell in the command? Since this process is run in the android runtime. – andy Jul 13 '16 at 13:23
-
OK, you havn't provide enough information. So you are running this in adb shell, on a rooted phone? Then why you are mentioning Mac and Windows? The link you provided is trying to run `adb` commands ON WINDOWS. – Kong Chun Ho Jul 13 '16 at 13:55
-
Yes. I am running this in adb shell on a rooted emulator. Sorry for not providing enough information. – andy Jul 13 '16 at 14:10
-
when i run this piece of code ---- FILE *in; char buff[512]; fflush(in); if(!(in = popen("dumpsys meminfo com.quixey.healthmonitor", "r"))){ LOG_HM("command failed"); return 1; } LOG_HM("command executed"); while(fgets(buff, sizeof(buff), in) != NULL){ LOG_HM("buff = %s", buff); }---------------- i am getting "Permission Denial: can't dump meminfo from from pid=21401, uid=10061" as the data read from the buff. – andy Jul 13 '16 at 14:25
-
The above mentioned code is being run in an android emulator. – andy Jul 13 '16 at 14:26
-
You still get permission denied with `su`? – Kong Chun Ho Jul 13 '16 at 15:19
-
Yes still getting permission denied su. – andy Jul 14 '16 at 06:18
-
If you run adb shell on your computer with above command, you have no problem? Have you installed some SU helper app like SuperSU? – Kong Chun Ho Jul 14 '16 at 09:00
-
I am able to get the details after executing the command in a rooted emulator. Thanks Kong chun. – andy Jul 14 '16 at 12:11