将 vCard 附加到电子邮件意图
Attach vCard to Email Intent
我正在尝试将 vCard (*.vcf) 附加到电子邮件意图中,如下所示:
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);
但是,该应用因以下异常而终止:
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) }
我也试过像这样显式设置类型:
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));
我正在尝试将 vCard (*.vcf) 附加到电子邮件意图中,如下所示:
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);
但是,该应用因以下异常而终止:
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) }
我也试过像这样显式设置类型:
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));