Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want use adb programmatically in my c++ project.I've downloaded the source code from google's website,but there is no document about how to built and use it on windows with c or c++.I don't want to use it with shell or commandline.For example,I just want implemnt the "adb devices" function with my c++ code,so what should I do about it?

What I have tried:

download src code,try to call it dynamic,There is almost no document about how to use it with c++.
Posted
Updated 23-Feb-17 0:44am

1 solution

As far as I understand you want to execute commands from within your app like the ADB command line client.

Then I would have a look at the ADB client sources to see how that communicates with the server background process. Together with the GitHub - cstyan/adbDocumentation: Better documentation of the ADB protocol, specifically for USB uses.[^] you should be able to communicate.

In other words:
Just use the ADB client sources in your project without the main() function implementation and call the functions as done by main.

Example for "adb devices":
clinet/main.cpp[^]
return adb_commandline(argc - 1, const_cast<const char**>(argv + 1));

commandline.cpp[^]
if (!strcmp(argv[0], "devices")) {
    const char *listopt;
    if (argc < 2) {
        listopt = "";
    } else if (argc == 2 && !strcmp(argv[1], "-l")) {
        listopt = argv[1];
    } else {
        fprintf(stderr, "Usage: adb devices [-l]\n");
        return 1;
    }
    std::string query = android::base::StringPrintf("host:%s%s", argv[0], listopt);
    printf("List of devices attached\n");
    return adb_query_command(query);
}

As you can see it builds a query string and calls adb_query_command.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900