SG Code - Design
  • Home
  • Impressum
.NET Projects
  • AndroidCtrl.dll
  • AndroidCtrlUI.dll
  1. You are here:  
  2. Home
  3. English (UK)
  4. AndroidCtrl.dll
  5. How - To
This article shows u how to use the Config & Deploy class.
  // Top of ur .cs file
  ...
  using AndroidCtrl;
  using AndroidCtrl.Tools;
  ...
This is an example for the remote configuration part:
  Config.Instance.Remote.Cache = "/cache/";
  Config.Instance.Remote.DalvikCache = "/data/dalvik-cache/";
  Config.Instance.Remote.Data = "/data/";
  Config.Instance.Remote.RecoveryCache = "/cache/recovery/";
  Config.Instance.Remote.SystemTmp = "/data/local/tmp/";
  
  Config.Instance.Remote.Provider.Contacts. ...
  Config.Instance.Remote.Provider.Telephony. ...
If u have set the paths to ur needs u are ready to start.

Now u can also deploy the needed ADB files if there is no ADB available.
Todo so u have to act like the following examples:
  // Deploy adb.exe, AdbWinApi.dll, AdbWinUsbApi.dll
  Deploy.ADB(); // use ADB.PATH_EXE
  Deploy.ADB("C:\\adb");
  
  // Deploy fastboot.exe, AdbWinApi.dll, AdbWinUsbApi.dll, libwinpthread-1.dll
  Deploy.Fastboot(); // use Fastboot.PATH_EXE
  Deploy.Fastboot("C:\\adb");
  
  // Deploy signapk.jar, testkey.pk8, testkey.x509.pem
  Deploy.Signer(); // use Signer.PATH_DIRECTORY
  Deploy.Signer("C:\\adb\\signer");
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)
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");
Sending KeyEvents via ADB

1. Send a single KeyEvent
// Top of ur .cs file
...
using AndroidCtrl.ADB.Binary;
//or
using AndroidCtrl.ADB.Socket;

using AndroidCtrl.ADB.Device.Input;
...

// Sends a single key-event to the device
(bool)ADB.Instance().Device.Input.KeyEvent(AKey);

// Sends a single key-event with the long pressed flag to the device
(bool)ADB.Instance().Device.Input.KeyEvent(AKey key, bool longPress);

// Sends a single key-event with the long pressed flag from a specific input source to the device
(bool)ADB.Instance().Device.Input.KeyEvent(InputSource source, AKey key, bool longPress);

//Sends a single, mapped (102 keys "en" layout), key-event to the device
(bool)ADB.Instance().Device.Input.MappedKeyEvent(int key, KeyMap map, bool alt, bool shift)

//Sends a single, mapped (102 keys "en, de" layout), key-event to the device
(bool)ADB.Instance().Device.Input.MappedKeyEvent(int key, KeyMap map, string twoLetterISOLanguageName, bool alt, bool shift)

2. Send an KeyEvent stack
// Top of ur .cs file
...
using AndroidCtrl.ADB.Binary;
//or
using AndroidCtrl.ADB.Socket;

using AndroidCtrl.ADB.Device.Input;
...

// Create a List<AKey>
List<AKey> _stack = new List<AKey>()
{
    AKey.Key1,
    AKey.Key2,
    AKey.Key3
};

// and send the stack to the phone
(bool)ADB.Instance().Device.Input.KeyEventStack(_stack);


// Create a List<KeyEvent>
List<KeyEvent> _stack = new List<KeyEvent>()
{
    new KeyEvent(AKey.Key1),
    new KeyEvent(AKey.Key2, true),
    new KeyEvent(AKey.Key3, false)
};

// and send the stack to the phone
(bool)ADB.Instance().Device.Input.KeyEventStack(_stack);
ADB Fastboot
// Top of ur .cs file
...
using AndroidCtrl;

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

// Reboot
ADB.Instance().Reboot(BootMode.Reboot);

// Reboot-Bootloader
ADB.Instance().Reboot(BootMode.Bootloader);

// Reboot-Recovery
ADB.Instance().Reboot(BootMode.Recovery);
// Top of ur .cs file
...
using AndroidCtrl;
using AndroidCtrl.Fastboot;
...

// Reboot
Fastboot.Instance().Reboot(BootMode.Reboot);

// Reboot-Bootloader
Fastboot.Instance().Reboot(BootMode.Bootloader);

NOTE
If u have more then one connected device and no device ID is selected in the class (so the base instance is selected) u'll reboot all connected devices! So it's better to call
ADB.Instance("device ID").Reboot(BootMode.Reboot);

Fastboot.Instance("device ID").Reboot(BootMode.Reboot);
if no device is selected.
  1. Device state check
  2. Monitor (ADB/Fastboot)
  3. Start/Stop (ADB/Fastboot)
  4. Getting Started

Page 1 of 2

  • 1
  • 2