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
Check which state a device currently have.
// Top of ur .cs file
...
using AndroidCtrl;
using AndroidCtrl.Tools;
...

DeviceState state = ToolBox.CheckDeviceState("deviceID");
Monitor, to check every 10 sec for an dis/-connected device.

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);

Callbacks for 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"
     });
}
ADB Fastboot
// Top of ur .cs file
...
using AndroidCtrl.ADB.Binary;
//or
using AndroidCtrl.ADB.Socket;
...

// Check if ADB is running
if (ADB.IsStarted)
{
	// Stop ADB
	ADB.Stop();
  
	// Force Stop ADB
	ADB.Stop(true);
}
else
{
	// Start ADB
	ADB.Start();
}
// Top of ur .cs file
...
using AndroidCtrl.Fastboot;
...

// Check if Fastboot is running
if (Fastboot.IsStarted)
{
	// Force Stop Fastboot
	Fastboot.ForceStop();
}
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();

Page 2 of 2

  • 1
  • 2