首页 > 解决方案 > 我可以使用 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();
        }

标签: c#androidadbcontactsvcf-vcard

解决方案


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

    }

推荐阅读