電話の連絡先をファイルに書き込んで、Eメールインテントアクションを介してエクスポートしています。SDカードにファイルを書き込むとエクスポートは正常に動作しますが、エミュレータの電話メモリにファイルを書き込むと、添付ファイルなしでメールが届きます。マイログに「アンロードされた添付ファイルはダウンロード用にマークされていません」と表示されます。
以下は私のコードです
file = new File(ctx.getFilesDir().getAbsolutePath(),"file.txt");
if (file.exists()) {
file.delete();
}
writer = new BufferedWriter(new FileWriter(file));
for (int i = 0; i < names.size(); i++) {
writer.write(names.get(i) + "," + phnno.get(i) + "\r\n");
}
writer.flush();
writer.close();
これは私のメールインテントです
Uri u1 = null;
u1 = Uri.fromFile(file);
System.out.println("u1 of URI"+u1); //u1 in logcat is "file:///data/data/com.android.contactxport/files/file.txt"
Intent sendIntent = new Intent(
Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_SUBJECT,
"Mail from ContactXPort App");
sendIntent
.putExtra(Intent.EXTRA_STREAM, u1);
sendIntent.setType("text/html");
startActivity(sendIntent);
編集:アンロードされた添付ファイルについての文書は言う
/**
* Check whether the message with a given id has unloaded attachments. If the message is
* a forwarded message, we look instead at the messages's source for the attachments. If the
* message or forward source can't be found, we return false
* @param context the caller's context
* @param messageId the id of the message
* @return whether or not the message has unloaded attachments
*/
public static boolean hasUnloadedAttachments(Context context, long messageId) {
Message msg = Message.restoreMessageWithId(context, messageId);
if (msg == null) return false;
Attachment[] atts = Attachment.restoreAttachmentsWithMessageId(context, messageId);
for (Attachment att: atts) {
if (!attachmentExists(context, att)) {
// If the attachment doesn't exist and isn't marked for download, we're in trouble
// since the outbound message will be stuck indefinitely in the Outbox. Instead,
// we'll just delete the attachment and continue; this is far better than the
// alternative. In theory, this situation shouldn't be possible.
if ((att.mFlags & (Attachment.FLAG_DOWNLOAD_FORWARD |
Attachment.FLAG_DOWNLOAD_USER_REQUEST)) == 0) {
Log.d(Logging.LOG_TAG, "Unloaded attachment isn't marked for download: " +
att.mFileName + ", #" + att.mId);
Attachment.delete(context, Attachment.CONTENT_URI, att.mId);
} else if (att.mContentUri != null) {
// In this case, the attachment file is gone from the cache; let's clear the
// contentUri; this should be a very unusual case
ContentValues cv = new ContentValues();
cv.putNull(AttachmentColumns.CONTENT_URI);
Attachment.update(context, Attachment.CONTENT_URI, att.mId, cv);
}
return true;
}
}
return false;
}
私が理解しているのは、パスがここでの問題ですが、ログに出力したときのパスはfynです。
どんな助けでも大歓迎です。前もって感謝します。