This article shows u how to use the Config & Deploy class.
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:
// 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");
Here i show u how to use the Logging.Logger class
// Top of ur .cs file using AndroidCtrl.Logging; // Activate the logger Logger.Instance.Active = true; // Here u can tell the log writer that it has to write each new log directly to the log-file Logger.Instance.WriteParts = true; // Log-file path (by default the file will be generated beside the dll) Logger.Instance.Path = "C:\\myLogFile.txt"; // Here are the events u can subscribe to, to get the logs in ur progam-code Logger.Instance.CallbackDebug += CallbackLogger; Logger.Instance.CallbackError += CallbackLogger; Logger.Instance.CallbackInfo += CallbackLogger; Logger.Instance.CallbackOutput += CallbackLogger; Logger.Instance.CallbackWarning += CallbackLogger; // This is the callback for all events public void CallbackLogger(object sender, LoggerArgs e) { App.Current.Dispatcher.Invoke((Action)delegate { // Do what u want with the log-data "e.Log" }); } // Define the log-level (that is a bit tricky but i'll explain) Logger.Instance.SetLogLevel(IDLog.DEBUG); // In the above example we "only" define the level "Debug", this will log all events! // U can also define the log levels like the following examples... // All events and all outputs Logger.Instance.SetLogLevel(IDLog.DEBUG, IDLog.OUTPUT); // This will do the same as the above example Logger.Instance.SetLogLevel(IDLog.ERROR, IDLog.INFO, IDLog.OUTPUT, IDLog.WARNING);Simply, u can define a "special" part u want to log, with-/out output or everything that happens. Here is a short explain about the log-levels.
- DEBUG = Logs everything that happens
- ERROR = Log all errors and *hopefully* all exceptions (caused by my dll)
- INFO = Log all calls and sub-call (currently "only" the ProcessModels namespace got he log-writer)
- OUTPUT = Log all outputs
- WARNING = Log all warnings
// 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(); }
Sending KeyEvents via ADB
1. Send a single KeyEvent
2. Send an KeyEvent stack
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);
// 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);
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.