我可以用adb和C#运行.vcf文件

问题描述 投票:1回答:1

我将.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
1个回答
0
投票
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();
        }

    }
© www.soinside.com 2019 - 2024. All rights reserved.