How do I launch an email application with file attachments from resources?

I am starting android development.

I am trying to start an external email application with intent and I want to attach a resource file to it.

I was able to attach the image resource file via the Gmail app, but for some reason the default email app doesn't attach it. Here is the code:

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
                    emailIntent.setType("image/png");

String path = "android.resource://" + getPackageName() + "/" + R.drawable.icon; 
Uri emailUri = Uri.parse(path);

emailIntent.putExtra(Intent.EXTRA_STREAM, emailUri);                        
startActivity(Intent.createChooser(emailIntent, "Send mail..."));

      

Also, even though it works in Gmail, the image file name and extension are lost when the file is sent. Is there a way to keep all the information associated with the file?

Help would be greatly appreciated!

+3


source to share





All Articles