コード例 #1
0
        private TcpClient startConnection()
        {
            Debug.Log("starting socket");
            tcpServer = new TcpListener(IPAddress.Parse(serverIP), hostPort);
            Debug.Log("waiting for device connection");
            tcpServer.Start();
            var acceptClientTask = tcpServer.AcceptTcpClientAsync();

            Debug.Log("starting android connection");
            //https://github.com/quamotion/madb
            var adbServer = new AdbServer();

            adbServer.StartServer(adbPath, true);
            adbClient = new AdbClient();
            var devices = adbClient.GetDevices();

            if (devices.Count == 0)
            {
                Debug.LogError("Error: Device not connected");
                return(null);
            }
            device = devices.Last();

            string command1  = @"am force-stop com.example.mediapipemultihandstrackingapp";
            var    receiver1 = new ConsoleOutputReceiver();

            adbClient.ExecuteRemoteCommand(command1, device, receiver1);
            Debug.Log("Stop remote app result: " + receiver1.ToString());

            Debug.Log("Resetting reverse connection");
            adbClient.RemoveAllReverseForwards(device);
            var reverseResult = adbClient.CreateReverseForward(
                device, "tcp:" + devicePort.ToString(), "tcp:" + hostPort.ToString(), true);

            string command2  = @"monkey -p com.example.mediapipemultihandstrackingapp -c android.intent.category.LAUNCHER 1";
            var    receiver2 = new ConsoleOutputReceiver();

            adbClient.ExecuteRemoteCommand(command2, device, receiver2);
            Debug.Log("Start remote app result: " + receiver2.ToString());

            return(acceptClientTask.Result);
        }