c# - 我可以使用 adb 和 C# 运行 .vcf 文件吗
问题描述
我将.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();
}
}
推荐阅读
- java - 转换为文档时如何在 XML 字符串中保留 Cdata 部分
- python - 使用 vispy Rectangle 创建条形图
- apache-spark - 扁平化pyspark中的复杂数据类型
- microsoft-graph-api - Exchange 混合 - 此邮箱尚不支持 404 REST API
- ruby-on-rails - 默认情况下在 bundle install 后执行 npm install
- sql - Ruby - 创建本地数据库并检查行是否已经存在
- android - 如何让android将应用程序识别为蓝牙外围设备(BLE设备)
- python - 虽然打开了 chrome,但找不到 Chromedriver
- r - 如何合并具有相同列名但列顺序不同的两个数据框
- sql - SQL 在具有最大值的表中查找值(结果必须是可编辑的)