如何使用服务中的意图(不在活动中)从.vcf文件导入联系人

时间:2014-03-11 10:04:06

标签: android

我可以在活动中导入.vcf文件中的联系人,但在服务中无法使用,任何人都可以帮助我。

2 个答案:

答案 0 :(得分:1)

检查一下:

Intent intent2 = new Intent(Intent.ACTION_VIEW);
    String storage_path = Environment.getExternalStorageDirectory().toString()+ File.separator + "Contacts.vcf";

intent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

intent2.setDataAndType(Uri.fromFile(new File(storage_path)),"text/x-vcard"); //storage path is path of your vcf file.

this.startActivity(intent2);

您需要添加标志FLAG_ACTIVITY_NEW_TASK才能从服务启动活动。

答案 1 :(得分:0)

试试这个

File file = new File(filePath);
Intent intent1 = new Intent();
intent1.setAction(Intent.ACTION_VIEW);
Uri data = Uri.fromFile(file);
intent1.setDataAndType(data, "text/x-vcard");
startActivity(intent1);