I'm writing this in Xamarin but the answer can be for Android Java (and I'll translate) or Xamarain.
I have a c# byte array (named attachment) of the contents of an gif like image so I cannot turn it into an image object as the contents inside would be lost. Think of it as a byte array of a file. I want to attach this image to an email. I have the following code.
//Create the email intent.
Intent emailIntent = new Intent(Intent.ActionSend);
//Add a flag to let the system know it can start this activity.
emailIntent.AddFlags(ActivityFlags.NewTask);
//Put the subject in the email.
emailIntent.PutExtra(Intent.ExtraSubject, subject);
//Put the body in the email.
emailIntent.PutExtra(Intent.ExtraText, body);
//Add the attachment.
emailIntent.PutExtra(Intent.ExtraStream, attachment);
//Set the intent type to the intent type of the email.
emailIntent.SetType("message/rfc822");
//Create a chooser intent to ask the user to choose the application for email.
Intent finalIntent = Intent.CreateChooser(emailIntent, "Send Email");
When I hit the code, it asks for an email program, I chose GMail, and I see my subject and body but no attachment.
How can I attach the byte array to the email to get it to attach?
Edit This question was marked as a duplicate. Here is why this question is NOT the same as How to attach a Bitmap when launching ACTION_SEND intent
That question: 1. Involves sending a bitmap. I don't have a bitmap but rather a in memory byte array. As mentioned, I CANNOT turn this byte array into a bitmap image as the contents inside will become compressed and modified. Even if I could get the bitmap to not be modified, every answer in that question runs a .compress on the bitmap. 2. This byte array should not be saved to the device for security. I generate the byte array and send it off. I would need a way to attach it in memory and not saving it to the file system.