![](/img/trans.png)
[英]Can I run an adb shell command in C# and not have it interrupted when I unplug the USB cable?
[英]Can I Run .vcf File With adb & C#
我將.vcf文件從PC推送到了Android設備; 我想運行此文件,並使用adb shell將所有聯系人導入設備。
這是我的C#函數:
private void adbcommand (string command)
{
Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.CreateNoWindow = true;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.FileName = @"D:\ADB\adb.exe";
startInfo.Arguments = command;
process.StartInfo = startInfo;
process.Start();
Console.WriteLine(process.StandardOutput.ReadToEnd());
process.Close();
}
private void button4_Click(object sender, EventArgs e)
{
adbcommand("shell pm clear com.android.providers.contacts");
adbcommand("shell mkdir /sdcard/contacts/");
string contactsFilePath = @"D:\mycontact.vcf";
adbcommand("push "+ contactsFilePath + " /sdcard/contacts/");
adbcommand("shell am start -t text/x-vcard -d file:///sdcard/contacts/mycontact.vcf -a android.intent.action.VIEW com.android.contacts");
private void adbcommand (string command)
{
Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.CreateNoWindow = true;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.FileName = @"D:\ADB\adb.exe";
startInfo.Arguments = command;
process.StartInfo = startInfo;
process.Start();
Console.WriteLine(process.StandardOutput.ReadToEnd());
process.Close();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.