A .NET Client for the Android Debug Bridge (ADB)
- Simple
- Thread-Safe
- Implemented Services:
- GetHostVersion (
host:version) - GetDevices (
host:devices) - TrackDevices (
host:track-devices) - Sync (
sync:)- Push (
SEND) - Pull (
RECV) - List (
LIST) - ListV2 (
LIS2) - Stat (
STAT) - StatV2 (
LST2/STA2)
- Push (
- Execute (
shell,v2:) - ScreenCapture (
framebuffer:)
- GetHostVersion (
- Pros:
- Simple
- Thread-Safe
- Async
- CancellationToken support
- Cons:
- Some services not (yet) implemented (pull requests are welcome)
varadbClient=newAdbServicesClient();inthostVersion=awaitadbClient.GetHostVersion();varadbClient=newAdbServicesClient();IList<(stringSerial,AdbConnectionStateState)>devices=awaitadbClient.GetDevices();This tracks all device changes (connect, disconnect, etc.) until the CancellationToken is cancelled (in this case, for 60 seconds)
varadbClient=newAdbServicesClient();varcts=newCancellationTokenSource(60000);awaitforeach((stringSerial,AdbConnectionStateState)deviceStateChangeinadbClient.TrackDevices(cts.Token)){[...]}varadbClient=newAdbServicesClient();using(varsyncClient=awaitadbClient.GetSyncClient("abcdefghijklmnop")){IList<StatV2Entry>entries=syncClient.ListV2("/");}using(varfs=File.OpenRead("test.mp3"))using(varsyncClient=awaitclient.GetSyncClient("abcdefghijklmnop")){awaitsyncClient.Push("/storage/emulated/0/Music/test.mp3",fs);}using(varfs=File.OpenWrite("test.mp3"))using(varsyncClient=awaitclient.GetSyncClient("abcdefghijklmnop")){awaitsyncClient.Pull("/storage/emulated/0/Music/test.mp3",fs);}varadbClient=newAdbServicesClient();intexitCode=awaitadbClient.Execute("abcdefghijklmnop","touch",newstring[]{"/storage/emulated/0/test.txt"},null,null,null);varadbClient=newAdbServicesClient();usingvarstdout=newMemoryStream();usingvarstderr=newMemoryStream();intexitCode=awaitadbClient.Execute("abcdefghijklmnop","ls",newstring[]{"-la","/storage/emulated/0/test.txt"},null,stdout,stderr);if(exitCode!=0)thrownewException(Encoding.UTF8.GetString(stderr.ToArray()));Console.WriteLine(Encoding.UTF8.GetString(stdout.ToArray()));// prints directory listingvaradbClient=newAdbServicesClient();usingvarstdin=newMemoryStream(Encoding.UTF8.GetBytes("Hello World"));usingvarstdout=newMemoryStream();usingvarstderr=newMemoryStream();intexitCode=awaitadbClient.Execute("abcdefghijklmnop","cat",newstring[]{},stdin,stdout,stderr);if(exitCode!=0)thrownewException(Encoding.UTF8.GetString(stderr.ToArray()));Console.WriteLine(Encoding.UTF8.GetString(stdout.ToArray()));// prints "Hello World"varadbClient=newAdbServicesClient();usingImageimg=awaitadbClient.ScreenCapture("abcdefghijklmnop");img.SaveAsPng("image.png");Please consider donating (via GitHub Sponsors) if this project is useful to you.
You can also support this project in other ways:
- by reporting bugs (via issues)
- by requesting features (via issues/discussions)
- by contributing code directly (via pull requests)
AI-generated contributions (code or issues) are not welcome and will not be considered.