附加电子名片到电子邮件意向
问题描述:
我试图将电子名片(*的.vcf)附加到电子邮件的意图,像这样:附加电子名片到电子邮件意向
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SENDTO dat=content://com.foo.fileprovider/external_files/Android/data/com.foo/files/generated.vcf (has extras) }
:
Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Shared Contact via the Foo App");
// vcfFile is a *.vcf file on local storage
Uri vCardUri = FileProvider.getUriForFile(this, "com.foo.fileprovider", vcfFile);
emailIntent.setData(vCardUri);
startActivity(emailIntent);
然而,应用程序会与下面的异常死亡
我也试图明确设置这样的类型:
emailIntent.setDataAndType(vCardUri, "text/x-vcard");
但是,它也有一个炸毁:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SENDTO dat=content://com.foo.fileprovider/external_files/Android/data/com.foo/files/generated.vcf typ=text/x-vcard (has extras) }
有没有办法将vCard附加到电子邮件意向?
答
共享文件仅记录在ACTION_SEND
中。将Uri
放入EXTRA_STREAM
。 (这可能也与ACTION_SENDTO
与一些电子邮件应用程序)。
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Shared Contact via the Foo App");
// vcfFile is a *.vcf file on local storage
Uri vCardUri = FileProvider.getUriForFile(this, "com.foo.fileprovider", vcfFile);
emailIntent.putExtra(Intent.EXTRA_STREAM, vCardUri);
emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
emailIntent.setType("text/x-vcard");
startActivity(Intent.createChooser(emailIntent, null));