1
我試圖將文本文件附加到電子郵件中,並且出現了一個奇怪的錯誤,我希望有人可以幫助我。當用戶從選擇器中選擇gmail應用程序時,它可以正常工作,但如果他們選擇了內置的郵件應用程序,他們會看到一個表示「無法附加文件」的敬酒。無法將文件附加到ACTION_SEND意圖
的代碼看起來是這樣的:
public static void sendMail(Context context, String emailBody, String emailSubject, String emailAddress, String attachmentFilename){
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { emailAddress});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
emailIntent.putExtra(Intent.EXTRA_TEXT, emailBody);
if(attachmentFilename != null) {
//Add the attachment by specifying a reference to our custom ContentProvider and the specific file of interest
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("content://" + Settings.VYPR_LOG_PROVIDER_AUTHORITY + "/" + attachmentFilename));
}
context.startActivity(emailIntent);
}
任何人有什麼可能這裏發生了什麼想法?我在這裏看到的大部分都與SD卡上的附件有關。我其實並沒有自己編寫這段代碼,但似乎不可能是這裏的問題,因爲確實在用戶選擇gmail應用程序而不是內置程序時工作。
在此先感謝!
這似乎與ContentProvider方法與許多ACTION_SEND處理程序不兼容有關。如果你想使用它,你最好的選擇是可能使gmail應用程序成爲強制性的。否則,您需要將文件保存到外部存儲器 – akhalsa 2013-04-25 14:37:12