String emailAddress[] = {""};
File externalStorage = Environment.getExternalStorageDirectory();
Uri uri = Uri.fromFile(new File(externalStorage.getAbsolutePath() + "/" + "com.example.pdf/sample.pdf"));
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL, emailAddress);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Text");
emailIntent.setType("application/pdf");
emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(emailIntent, "Send email using:"));
logcat 中显示的消息是:
gMail Attachment URI: file:///mnt/sdcard/com.example.pdf/sample.pdf
gMail type: application/pdf
gmail name: sample.pdf
gmail size: 0
问题是样本 pdf 的大小为 0,因此 pdf 不会作为电子邮件中的附件发送。谁能告诉我我做错了什么?