//EMAIL SENDING CODE FROM ASSET FOLDER
email = editTextEmail.getText().toString();
subject = editTextSubject.getText().toString();
message = editTextMessage.getText().toString();
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("file/html");
emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("content://com.example.deepa.xmlparsing/file:///android_assets/Combination-1.html"));
startActivity(Intent.createChooser(emailIntent, "Send email using"));
Finally, I'm getting the file from asset folder (Combination-1.html).
It is getting
Runtime error file not found exception.
Is there any other way to send file attachment?
The easiest way to send an email is to create an Intent of type ACTION_SEND :
To attach a single file, add some extended data to Intent :
Or use Html.fromHtml() to build html content:
For multiple attachments:
Finish with a call to startActivity() passing intent.
You can not share Asset folder file to other application without ContentProvider. You can send file which can be accesible for every application.like some whare in intenal phone memory or sd card.
Sharing Asset Check This Answer of @CommonsWare
Or Read your text file and use @RonTLV Answer and mail.
Or Copy File in intenal memory and add to sending launch. Hope this answer will help.
Create a File object of your asset folder file and attach this object to your email Intent.
And as mentioned in your Question runtime error file not found exception this may be cause the URL "file:///android_asset/" doesn't point to a particular directory, it is only used by WebView to address assets. Pulled that from
you can open this as an input stream and covert this
InputStream
toFile
Send this file object in email as follow.
Where
Intent.ACTION_SEND
used to send Email ,Intent.EXTRA_STREAM
for the attachments with email. you can have multipleIntent.EXTRA_STREAM
in single intent to refer multiple attachments withintent.setAction(Intent.ACTION_SEND_MULTIPLE);
.intent.setType(String mimeType)
input param is represent the MIME type data that you want to get in return from firing intent(here intent instance).where setype can be