Skip to content

Latest commit

History

40 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

AdbClient.NET

A .NET Client for the Android Debug Bridge (ADB)

Nuget

Features

  • 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)
    • Execute (shell,v2:)
    • ScreenCapture (framebuffer:)

Compared to madb / SharpAdbClient

  • Pros:
    • Simple
    • Thread-Safe
    • Async
    • CancellationToken support
  • Cons:
    • Some services not (yet) implemented (pull requests are welcome)

Examples

Get ADB host version

varadbClient=newAdbServicesClient();inthostVersion=awaitadbClient.GetHostVersion();

Get Devices

varadbClient=newAdbServicesClient();IList<(stringSerial,AdbConnectionStateState)>devices=awaitadbClient.GetDevices();

Track Devices

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)){[...]}

List root directory

varadbClient=newAdbServicesClient();using(varsyncClient=awaitadbClient.GetSyncClient("abcdefghijklmnop")){IList<StatV2Entry>entries=syncClient.ListV2("/");}

Upload file to device

using(varfs=File.OpenRead("test.mp3"))using(varsyncClient=awaitclient.GetSyncClient("abcdefghijklmnop")){awaitsyncClient.Push("/storage/emulated/0/Music/test.mp3",fs);}

Download file from device

using(varfs=File.OpenWrite("test.mp3"))using(varsyncClient=awaitclient.GetSyncClient("abcdefghijklmnop")){awaitsyncClient.Pull("/storage/emulated/0/Music/test.mp3",fs);}

Execute command

Simple

varadbClient=newAdbServicesClient();intexitCode=awaitadbClient.Execute("abcdefghijklmnop","touch",newstring[]{"/storage/emulated/0/test.txt"},null,null,null);

With stdout/stderr redirection

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 listing

With everything redirected

varadbClient=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"

Capture screen

Capture and save as png

varadbClient=newAdbServicesClient();usingImageimg=awaitadbClient.ScreenCapture("abcdefghijklmnop");img.SaveAsPng("image.png");

Support

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.

About

A .NET Client for the Android Debug Bridge (ADB)

Topics

Resources

Stars

15 stars

Watchers

3 watching

Forks

Packages

Used by

Contributors

Languages