How to send a message from Android to Windows using USB

前端 未结 2 1235
旧巷少年郎
旧巷少年郎 2020-12-02 19:35

I am a complete noob at Android, only at the level of basic (1 or 2 line) Activities activated by buttons, but I would like to create a really simple app that, when I tap th

2条回答
  •  無奈伤痛
    2020-12-02 20:11

    Using Managed.adb in c#

    AndroidDebugBridge bridge = AndroidDebugBridge.
    CreateBridge(@"C:\Users\bla\AppData\Local\Android\Sdk\platform-tools\adb.exe", true); 
    
    List devices = AdbHelper.Instance.
    GetDevices(AndroidDebugBridge.SocketAddress); 
    
    devices[0].CreateForward(38300, 38300); 
    

    Then create a server socket on android to that port.

    server = new ServerSocket(38300);
                    server.setSoTimeout(TIMEOUT * 1000);
                    socket = server.accept();
    

    and client socket on C#

      TcpClient clientSocket = new System.Net.Sockets.TcpClient();
                    clientSocket.Connect("127.0.0.1", 38300);
    

提交回复
热议问题