45

I have a FileProvider which I use when attaching files on the SD Card to emails.

This works on Lollipop and Marshmallow in any app using an Intent.

However, in Android 4.3 when using the Email app, the attachment appears in the email when composing but when it's sent, on the recipient's end the attachment isn't there. For all other tested applications it works (Gmail, Evernote, Drive).

I am not deleting the file before the email is sent.

Here is my code.

final Intent fileShareIntent = new Intent(android.content.Intent.ACTION_SEND);
fileShareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, emailSubject);
fileShareIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailText);
Uri fileUri = STFileProvider.getContentUriForProvidedFile(this,file);
fileShareIntent.putExtra(Intent.EXTRA_STREAM,fileUri);
fileShareIntent.setType(mimeType);
fileShareIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{prefs.getString("default_email_preference", "")});
startActivity(Intent.createChooser(fileShareIntent,getString(R.string.share_with)));

EDIT I have found a the Exception's stack trace which is inline with @CommonsWare's suggestion

01-04 17:39:00.430 6828-6828/? W/System.err: java.lang.IllegalArgumentException: column '_data' does not exist
01-04 17:39:00.430 6828-6828/? W/System.err:     at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:303)
01-04 17:39:00.430 6828-6828/? W/System.err:     at android.database.CursorWrapper.getColumnIndexOrThrow(CursorWrapper.java:78)
01-04 17:39:00.430 6828-6828/? W/System.err:     at com.android.email.activity.MessageCompose.getFilePath(MessageCompose.java:21476)
01-04 17:39:00.430 6828-6828/? W/System.err:     at com.android.email.activity.MessageCompose.getFilePathOfAttachment(MessageCompose.java:17710)
01-04 17:39:00.430 6828-6828/? W/System.err:     at com.android.email.activity.MessageCompose.addAttachment(MessageCompose.java:19140)
01-04 17:39:00.430 6828-6828/? W/System.err:     at com.android.email.activity.MessageCompose.access$11000(MessageCompose.java:362)
01-04 17:39:00.430 6828-6828/? W/System.err:     at com.android.email.activity.MessageCompose$LoadAttachmentsTaskFromIntent.onProgressUpdate(MessageCompose.java:15277)
01-04 17:39:00.430 6828-6828/? W/System.err:     at com.android.email.activity.MessageCompose$LoadAttachmentsTaskFromIntent.onProgressUpdate(MessageCompose.java:15101)
01-04 17:39:00.430 6828-6828/? W/System.err:     at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:647)
01-04 17:39:00.430 6828-6828/? W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:99)
01-04 17:39:00.430 6828-6828/? W/System.err:     at android.os.Looper.loop(Looper.java:176)
01-04 17:39:00.430 6828-6828/? W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5419)
01-04 17:39:00.430 6828-6828/? W/System.err:     at java.lang.reflect.Method.invokeNative(Native Method)
01-04 17:39:00.430 6828-6828/? W/System.err:     at java.lang.reflect.Method.invoke(Method.java:525)
01-04 17:39:00.430 6828-6828/? W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
01-04 17:39:00.430 6828-6828/? W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
01-04 17:39:00.430 6828-6828/? W/System.err:     at dalvik.system.NativeStart.main(Native Method)
18
  • 1
    You might try this fix. I have a packaged version of that solution in my CWAC-Provider library. Commented Jan 4, 2016 at 17:07
  • I don't think this is the same issue. It's not crashing at all, the attachment just isn't staying attached when sending. Commented Jan 4, 2016 at 17:19
  • I haven't used the Email app. If it is showing some details in its UI that could only be obtained from the actual stream, then you're right, this can't be the issue. If, OTOH, the only stuff you see in the UI is stuff that could be determined without actually using the Uri contents, then it may be they are just catching the exception with a broken DATA-dependent implementation. Since you already have a custom FileProvider subclass, adding my LegacyCompatCursorWrapper should only take ~6 lines or so (dependency + query()), so it may be worth a test. Commented Jan 4, 2016 at 17:21
  • At the moment I don't do anything with the CRUD operations. In fact, after following a tutorial all they do is throw new RuntimeExceptions. I'm not sure how to use your LegacyCompatCursorWrapper with my subclass of FileProvider as I don't have a Cursor to begin with Commented Jan 4, 2016 at 17:39
  • @CommonsWare please see original question for stack trace update Commented Jan 4, 2016 at 17:41

2 Answers 2

1

I know, it might be too late, but I stumbled over the exact same problem and it took me a while to find my mistake:

My fault was, that I deleted the original file I like to send when my app got back from the email-app. (I tried to clean up temporary files)

Unfortunately, the email-app does not send the mail right away nor does it make a copy of the attachment. So when the file will be deleted before the mail was sent (as I did) the attachment got lost.

This behavior is different from most other apps (including Gmail-app) that take care of the file before returning back to my app.

Sign up to request clarification or add additional context in comments.

Comments

0

It is about database sqlite .

there are 2 possibilities:

  1. You changed something in database or table.

or

  1. Your accessing field which is may be not correct or not present in code.

Solution:

  1. Uninstall app and test again with new changes in db.

  2. correct you database code.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.