【问题标题】:Can I Run .vcf File With adb & C#我可以使用 adb 和 C# 运行 .vcf 文件吗
【发布时间】:2019-03-27 21:28:36
【问题描述】:

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

【问题讨论】:

标签: c# android adb contacts vcf-vcard


【解决方案1】:
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();
        }

    }

【讨论】:

    猜你喜欢
    • 2014-05-04
    • 1970-01-01
    • 2019-10-20
    • 1970-01-01
    • 2019-04-16
    • 2016-10-01
    • 2016-12-25
    • 2020-05-04
    • 2017-07-05
    相关资源
    最近更新 更多