2

I'm running adb shell commands using the method described below

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();

On the android phone I'm starting an app that records a video so cmd = "adb shell am startservice -n com.xxx.xxx/.xxx".

The problem is that I need to unplug the USB cable after I start recording video. If I do that, the resulting video file won't play. Sometimes it's 0KB. If I leave the USB cable connected, then the video is fine.

Is there a way to perform the adb command so that the video will continue recording after I unplug the USB cable? Everything is fine when I enter the command from the command prompt and unplug the USB cable.

5
  • Possible duplicate of How to run command as background process using ADB? Commented Dec 23, 2015 at 19:14
  • It seems that you had no problem with "Running adb shell commands from C# application". Why did you put it in your title? Commented Dec 23, 2015 at 19:16
  • I was having trouble thinking of a title that wasn't as long as the phone book. Thanks for the constructive criticism. It's edited now Commented Dec 23, 2015 at 20:14
  • I keep getting "nohup: not found" or "daemonize: not found" when I try the suggestions from the above link Commented Dec 23, 2015 at 23:42
  • 1
    for devices which do not have nohup - install busybox and use busybox nohup instead Commented Dec 24, 2015 at 3:10

1 Answer 1

0

Try the following instead:

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

My primary language i use is Visual Basic, So this might need a little work to get working correctly

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.