public void ConnectPhone(string Serial) { StartServer(); var dns = GetCacheDnsEndPoint(Serial); if (dns != null) { AdbClient.Connect(dns.Host); DevicesConnected.Add(Serial, dns); return; } var deviceData = AdbClient.GetDevices().First(x => x.Serial == Serial); // Get ip addresse of the device var receiver = new ConsoleOutputReceiver(); AdbClient.ExecuteRemoteCommand("ip addr show wlan0", deviceData, receiver); var ip = receiver.ToString().Split('\n').Where(x => x.Contains("inet")).First() .Trim().Split(' ')[1].Split('/').First(); // Setup the tcpip port++; CommandADB.StartTcpip(Serial, port); AdbClient.Connect(ip); dns = new DnsEndPoint(ip, port); DevicesConnected.Add(Serial, dns); DeviceCache.Add(Serial, dns); }
void UploadFile(SharpAdbClient.DeviceData device, string fileLocal, string fileRemote) { //var device = AdbClient.Instance.GetDevices().First(); try { AdbClient adbClient = new AdbClient(); try { adbClient.Connect(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort)); adbClient.ExecuteRemoteCommand("mkdir " + Constants.remotePath, device, new myReceiver()); }catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } using (SyncService service = new SyncService(new AdbSocket(adbClient.EndPoint), device)) using (Stream stream = File.OpenRead(fileLocal)) { service.Push(stream, fileRemote, 444, DateTime.Now, null, CancellationToken.None); } textBox1.Text = "File send successfully"; } catch (Exception ex) { textBox1.Text = ex.Message + " Is MTP enabled?"; } }
/// <summary> /// Connect to a Android device over a Network /// </summary> /// <param name="ipAddressDevice"> The IP address of the Android device </param> /// <returns> true for a succeed and false for failure </returns> public static bool ConnectWirelessClient(String ipAddressDevice) { try { Client.Connect(ipAddressDevice); } catch (InvalidOperationException) { return(false); } return(true); }
public DeviceInfo ConnectToDevice(string host = "127.0.0.1", int port = 5037, string id = "") { _device = GetDeviceById(id); if (_device != null) { return(new DeviceInfo(_device ?? null, new ConsoleOutputReceiver())); } Client.Connect(new IPEndPoint(IPAddress.Parse(host), port)); _device = Client.GetDevices().FirstOrDefault(); if (_device == null) { Restart(); return(ConnectToDevice(host, port, id)); } return(new DeviceInfo(_device, new ConsoleOutputReceiver())); }
/// <summary> /// Select a device based on adb ip:port format string /// </summary> /// <param name="adbipsocket">ip:port format string</param> internal bool SelectDevice(string adbipsocket) { adbipport = adbipsocket; logger.WritePrivateLog("Finding " + adbipport); client.Connect(new DnsEndPoint(adbipsocket.Split(':')[0], Convert.ToInt32(adbipsocket.Split(':')[1]))); foreach (var device in client.GetDevices()) { if (device.ToString() == adbipsocket) { selectedDevice = device; Console.Out.WriteLine("SelectDevice Success"); return(true); } } logger.WritePrivateLog("No such device found"); return(false); }
private void Button_Click(object sender, RoutedEventArgs e) { try { //txtIP.Text = ((DeviceData)lstDevices.SelectedItem).Serial.ToString(); adbClient.Connect(txtIP.Text); MessageBox.Show("Operation Success. Disconnect your device from PC"); Properties.Settings.Default.LastIp = txtIP.Text; Properties.Settings.Default.Save(); } catch (Exception) { MessageBox.Show("Operation failed"); return; } }
internal void InitClient() => Client.Connect(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort));