Reputation: 146
I'm writing a small app for sending emails. I'm able to send emails just fine using an intent, which opens the default email application.
The code I wrote for this works fine and is as follows:
private void sendMe(String address, String subject, String emailBody){
String uriText =
"mailto:" + address +
"?subject=" + Uri.encode(subject) +
"&body=" + Uri.encode(emailBody);
Uri uri = Uri.parse(uriText);
Intent sendIntent = new Intent(Intent.ACTION_SENDTO);
sendIntent.setData(uri);
startActivity(Intent.createChooser(sendIntent, "Send email"));
emailBody = "";
}
But, if I send two emails one after the other and delete the draft via the Android email app GUI, if I try to send a second email using my app, the body of the previous email remains in the second email.
Is there an existing solution for deleting the existing email text from the email app or do I need to use a separate email client library to do this?
Upvotes: 2
Views: 468
Reputation: 146
I've figured it out.
The issue had nothing to do with draft support in an android email app as I suspected, it was related to my own emailBody String not being erased before sending the intent to the android email app. My variable and therefore the intent contained the body of multiple emails which were sent to the app.
I moved the line emailBody = ""; to a different thread and made sure it executed before sending the intent.
Upvotes: 0
Reputation: 939
That's usually caused by having your e-mail client/app setup to save drafts to the server. Change the setting to save drafts locally and all those saved partial copies should stop.
Upvotes: 1
Reputation: 1007266
Is there an existing solution for deleting the existing email text from the email app
There are hundreds, perhaps thousands, of email apps for Android. This includes both pre-installed apps and apps that users install from the Play Store or other distribution channels. The behavior of each of these apps is up to the developers of those apps. Of note, none are required to have support for email drafts, let alone offer outside parties control over such drafts.
Your job is to ensure that you are putting the right text in the request. For example, your emailBody = ""
statement in your source code is pointless. So long as your request has the desired information, everything after that is up to the other app's developers and the user.
Upvotes: 1