SG Code - Design
  • Home
  • Impressum
.NET Projekte
  • AndroidCtrl.dll
  • AndroidCtrlUI.dll
  1. Aktuelle Seite:  
  2. Home
  3. Deutsch (DE)
  4. AndroidCtrl.dll
  5. How - To
There is a call u need, but it's not included in my dll?! What u have to do? (Nothing easier than this!)

ADB Fastboot Signer
// Top of ur .cs file
...
using AndroidCtrl;
using AndroidCtrl.ADB;

using AndroidCtrl.ADB.Binary;
//or
using AndroidCtrl.ADB.Socket;

using AndroidCtrl.Tools;
...

ADB.Instance().Execute("version", int timeOut = 0);

// or
ADB.Instance().Execute("shell id", int timeOut = 0);

// Shell cmd call
ADB.Instance().ShellCmd("id", int timeOut = 0);

// Shell cmd Su call
ADB.Instance().Device.Su.ShellCmd("id", int timeOut = 0);

// ShellCmd() and Su.ShellCmd()
...ShellCmd(string cmd, int timeout = 0)
...ShellCmd(string cmd, CancellationToken cancellationToken, int timeout = 0)
...ShellCmd(string cmd, ShellDataEventHandler shellDataEventHandler, int timeout = 0)
...ShellCmd(string cmd, ShellDataEventHandler shellDataEventHandler, CancellationToken cancellationToken, int timeout = 0)

// ShellCmdHRes() and Su.ShellCmdHRes()
...ShellCmdHRes(string cmd, int timeout = 0)
...ShellCmdHRes(string cmd, CancellationToken cancellationToken, int timeout = 0)
...ShellCmdHRes(string cmd, ShellDataEventHandler shellDataEventHandler, int timeout = 0)
...ShellCmdHRes(string cmd, ShellDataEventHandler shellDataEventHandler, CancellationToken cancellationToken, int timeout = 0)

// Creating an List<string> cmd stack
List<string> stack = new List<string>() { "id", "id", "id" };

// Shell cmd stack call
ADB.Instance().ShellCmdStack(stack, int timeOut = 0);

// Shell cmd Su stack call
ADB.Instance().Device.Su.ShellCmdStack(stack, int timeOut = 0);

// ShellCmdStack() and Su.ShellCmdStack()
...ShellCmdStack(IEnumerable cmdStack, int timeout = 0)
...ShellCmdStack(IEnumerable cmdStack, CancellationToken cancellationToken, int timeout = 0)
...ShellCmdStack(IEnumerable cmdStack, ShellDataEventHandler shellDataEventHandler, int timeout = 0)
...ShellCmdStack(IEnumerable cmdStack, ShellDataEventHandler shellDataEventHandler, CancellationToken cancellationToken, int timeout = 0)
// Top of ur .cs file
...
using AndroidCtrl;
using AndroidCtrl.Tools;
using AndroidCtrl.Fastboot;
...

Fastboot.Instance().Execute("help", int timeOut = 0);

// or
Fastboot.Instance().Execute("erase cache", int timeOut = 0);

// or (with quoted params)
Fastboot.Instance().Execute("erase \"cache\"", int timeOut = 0);

// or (with quoted params using dll tools)
Fastboot.Instance().Execute(String.Join(" ", "erase", ToolBox.Quote("cache")), int timeOut = 0);
// Top of ur .cs file
...
using AndroidCtrl;
using AndroidCtrl.Signer;
...

Signer.Instance.Execute("cmd", int timeOut = 0);

NOTE
timeout is by default -1 this implies infinite, but u can set also 250 for 250 milliseconds or an individual value. The timeout parameter is to tell my method how long it have to wait for an result before it ends. The return of ADB.Instance().Execute(), Fastboot.Instance().Execute() and Signer.Instance.Execute() are always a IEnumerable<string>.
(int timeout = 0, means that the class internal timeout parameter is used. This parameter is also by default -1)
If u want to include AndroidCtrl.dll in ur current or new .NET project, you have to do the following steps.
  • Open for example VisualStudio and ur project
  • Go to References
  • Add the AndroidCtrl.dll
  • (Optional) place the AndroidCtrl.xml beside the AndroidCtrl.dll (This will give u the markup in VisualStudio)

And in ur code u have to assign the namespaces like:
// Top of ur .cs file
...
using AndroidCtrl;
using AndroidCtrl.ADB;

using AndroidCtrl.ADB.Binary;
//or
using AndroidCtrl.ADB.Socket;

using AndroidCtrl.Fastboot;
using AndroidCtrl.Signer;
using AndroidCtrl.Tools;
...
To access the ADB/Fastboot/Signer class you can act like the following examples.

1. Deploy the needed adb.exe, fastboot.exe, AdbWinApi.dll, AdbWinUsbApi.dll, libwinpthread-1.dll, signapk.jar, testkey.pk8 and testkey.x509.pem.
Deploy.ADB();
Deploy.Fastboot();
Deploy.Signer();


1.1. Integrity check
// Check if everything is on it's place
(bool)Binary.ADB.IntegrityCheck();
(bool)Fastboot.IntegrityCheck();
(bool)Signer.IntegrityCheck();

// Check if there is already a server running and if so,
// if it has the same version as ours
(bool)Binary.ADB.IntegrityVersionCheck();


2. General ADB/Fastboot connection, without taking care about the device ID
// Starting ADB-Server
ADB.Start();

ADB.Instance().TheMethodToCall();

Fastboot.Instance().TheMethodToCall();


2.1. Device specific ADB/Fastboot instance
// Starting ADB-Server
ADB.Start();

ADB.Instance("Device ID").TheMethodToCall();

Fastboot.Instance("Device ID").TheMethodToCall();


2.2. Device specific ADB/Fastboot instance with instance selection. This will select the given device ID in the whole dll instance, so u can access it from everywhere in ur code via ADB.Instance() or Fastboot.Instance().
// Starting ADB-Server
ADB.Start();

ADB.Select("Device ID");
ADB.Instance().TheMethodToCall();

Fastboot.Select("Device ID");
Fastboot.Instance().TheMethodToCall();

2.3. Signer call
Signer.Instance.TheMethodToCall();
Directory Reading/Parsing.

1. Callback reading/parsing
// Top of ur .cs file
...
using AndroidCtrl.ADB.Binary;
//or
using AndroidCtrl.ADB.Socket;

using AndroidCtrl.ADB.Device.IO;
...

// Set the directory to get
Directories _ADBD = ADB.Instance().Device.IO.Directories("directory path");

// Use the callback parser for directories only
(void)_ADBD.GetDirectories(DirectoryParserEventHandler);

// Or the callback parser for files only
(void)_ADBD.GetFiles(DirectoryParserEventHandler);

// Or the callback parser for both, files and directories
(void)_ADBD.Parse(DirectoryParserEventHandler);

// Parser callback, this function will be raised after the parser is done with an
// item, so u can get the items in real time from the parser.
public void DirectoryParserEventHandler(object sender, DirectoryParserEventArgs e)
{
     App.Current.Dispatcher.Invoke((Action)delegate
     {
          // Do what u want with the output "e.Element"
          // Add it to an list/-treeview for example
     });
}

2. Normal reading/parsing
// Top of ur .cs file
...
using AndroidCtrl.ADB.Binary;
//or
using AndroidCtrl.ADB.Socket;

using AndroidCtrl.ADB.Device.IO;
...

IEnumerable<IFileSystemItem> elements = ADB.Instance().Device.IO.Directories("directory path").Parse();

NOTE
The difference is, if u use Shell to parse the items it will need much more time if u have a lot of symlinks in the directory, because, my DataModel differs between symlink-file and symlink-folder, so the user have to wait a lot of time for the result. If u use BusyBox this will not happen, but if the device is not rooted we need to work with the Shell. So its better to use the 1st way, because the parser will give u any item direct after the parser is done with it.

3. Raw reading
// Top of ur .cs file
...
using AndroidCtrl.ADB.Binary;
//or
using AndroidCtrl.ADB.Socket;

using AndroidCtrl.ADB.Device.IO;
...

// This will give u the raw items from the Shell/BusyBox request
IEnumerable<string> elements = ADB.Instance().Device.IO.Directories("directory path").ReadRaw();

// You can parse it ur own or using 
IFileSystemItem element = ADB.Instance().Device.IO.Directories("directory path").ParseItem("Raw item");
Monitor, um alle 10 sec zu prüfen ob ein Gerät angeschlossen oder getrennt wurde.

ADB Fastboot
// Top of ur .cs file
...
using AndroidCtrl;

using AndroidCtrl.ADB.Binary;
//or
using AndroidCtrl.ADB.Socket;
...

// Assign the callbacks
ADB.Monitor.Added += Added;
ADB.Monitor.Changed += Changed;
ADB.Monitor.Removed += Removed;

// Start the monitor
ADB.Monitor.Start()

// Stop the ADB monitor
ADB.Monitor.Stop();

// Stop the ADB monitor and release all event handler
ADB.Monitor.Stop(true);
// Top of ur .cs file
...
using AndroidCtrl;
using AndroidCtrl.Fastboot;
...

// Assign the callbacks
Fastboot.Monitor.Added += Added;
Fastboot.Monitor.Changed += Changed;
Fastboot.Monitor.Removed += Removed;

// Start the monitor
Fastboot.Monitor.Start()

// Stop the Fastboot monitor
Fastboot.Monitor.Stop();

// Stop the Fastboot monitor and release all event handler
Fastboot.Monitor.Stop(true);

Callback für ADB/Fastboot
// Top of ur .cs file
using System.Linq;
...
using AndroidCtrl;
...

// Callback for both (ADB/Fastboot)
private void Added(object sender, MonitorAddedEventArgs e)
{
     App.Current.Dispatcher.Invoke((Action)delegate
     {
          // Do what u want with the "IDeviceInfo[] e.Devices.ToArray()"
          // The "sender" is a "string" and returns "adb" or "fastboot"
     });
}

private void Changed(object sender, MonitorChangedEventArgs e)
{
     App.Current.Dispatcher.Invoke((Action)delegate
     {
          // Do what u want with the "IDeviceInfo[] e.Devices.ToArray()"
          // The "sender" is a "string" and returns "adb" or "fastboot"
     });
}

private void Removed(object sender, MonitorRemovedEventArgs e)
{
     App.Current.Dispatcher.Invoke((Action)delegate
     {
          // Do what u want with the "IDeviceInfo[] e.Devices.ToArray()"
          // The "sender" is a "string" and returns "adb" or "fastboot"
     });
}
Check which state a device currently have.
// Top of ur .cs file
...
using AndroidCtrl;
using AndroidCtrl.Tools;
...

DeviceState state = ToolBox.CheckDeviceState("deviceID");

Seite 2 von 2

  • 1
  • 2