我将.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();
}
}