SharpAdb / AdvancedSharpAdbClient

AdvancedSharpAdbClient is a .NET library that allows .NET, Mono and Unity applications to communicate with Android devices. It's improved version of SharpAdbClient.
https://sharpadb.github.io
Apache License 2.0
198 stars 54 forks source link

How to execute simple adb commands not abd shell ones? #65

Closed Chicagorange closed 1 month ago

Chicagorange commented 1 year ago

What can we do for you?

Hello,

Is there a way to send simple adb commands?

I would like to retrieve a folder from my device but I can't find a way to do it.

Thank you.

wherewhere commented 1 year ago

This project is direct communicate with adb service. If you want to communicate with adb client, just use Process to send command.

Chicagorange commented 1 year ago

Thanks for your quick reply.

Actually I don't know the difference between adb shell and adb but I have been able to send my command using Process. That was my previous solution to send adb and adb shell commands. I just thought that I could send all commands using AdvancedSharpAdbClient.

wherewhere commented 1 year ago

adb.exe is adb client. It communicates with adb service to process commands. This project is a csharp version of adb client to connect with adb server directly. Some command is not available in adb server, such as adb install-multiple, which is approved by adb client. If you want to send not-shell command, you can use:

var adbSocketFactory = Factories.AdbSocketFactory;
var EndPoint = new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort);
using IAdbSocket socket = adbSocketFactory(EndPoint); 
await socket.SendAdbRequestAsync("your command", cancellationToken); 
AdbResponse response = await socket.ReadAdbResponseAsync(cancellationToken); 
string result = await socket.ReadStringAsync(cancellationToken);

I haven't found the list of adb service command. I only known that if you want to send shell ls, the command is shell:ls. And if you want to send version, it is host: version. You can find this commands by search this repo.