我正在使用下面介绍的方法运行adb shell命令
System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd.exe", "/c " + cmd);
procStartInfo.RedirectStandardInput = true;
procStartInfo.RedirectStandardOutput = true;
procStartInfo.RedirectStandardError = true;
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = true;
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = procStartInfo;
proc.Start();
在Android手机上我启动了一个记录视频的应用程序,因此cmd =" adb shell am startservice -n com.xxx.xxx/.xxx"。
问题是我开始录制视频后需要拔下USB线。如果我这样做,生成的视频文件将无法播放。有时它是0KB。如果我连接了USB线,那么视频就可以了。
有没有办法执行adb命令,以便在拔下USB连接线后视频会继续录制?当我从命令提示符输入命令并拔下USB电缆时,一切都很好。
答案 0 :(得分:0)
请尝试以下方法:
string cmd = " shell am startservice -n com.xxx.xxx/.xxx";
using (Process proc = new process())
{
System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd.exe");
procStartInfo.RedirectStandardInput = true;
procStartInfo.RedirectStandardOutput = true;
procStartInfo.RedirectStandardError = true;
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = true;
proc.StartInfo = procStartInfo;
proc.Start();
proc.StandardInput.Writeline("adb devices");
proc.StandardInput.Writeline("adb shell getprop dhcp.wlan0.ipaddress"); // this will not work on some newer os
string deviceip = proc.StandardOutput.Readline();
proc.StandardInput.Writeline("adb tcpip 5555"); // this will turn on ADB to wifi on port 5555
proc.StandardInput.Writeline("adb connect " + deviceip + " 5555"); // this allows you to at this point unplug your device
proc.StandardInput.Writeline("adb -s " + deviceip + ":5555" + cmd); // this connects running the command on the specific ip address so when you disconnect usb it will continue creating movie
proc.WaitForExit();
} // this might not be correct wait command
我使用的主要语言是Visual Basic,所以这可能需要一些工作才能正常工作