Search code examples
androidandroid-intentgmail

How can I avoid saving draft of gmail intent?


Part of my application functionality is to automatically fill gmail message subject, text, recipients and attach a photo. But I don't want to save this message as draft when I exit gmail intent without sending out the message.

How can I disable saving a draft before starting intent from my application? Is there a possible solution or workaround?

My intent code:

// fill email message fields for sending out report
    public void composeEmail(String[] addresses, String subject) {
        File filelocation = new File(mCurrentPhotoPath);
        Uri photoUri = Uri.fromFile(filelocation);
        Intent intent = new Intent(Intent.ACTION_SENDTO);
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.setData(Uri.parse("mailto:")); // only email apps should handle this
        intent.putExtra(Intent.EXTRA_EMAIL, addresses);
        intent.putExtra(Intent.EXTRA_SUBJECT, subject);
        intent.putExtra(Intent.EXTRA_STREAM, photoUri);
        if (intent.resolveActivity(getPackageManager()) != null) {
            startActivity(intent);
        }
    }

Solution

  • Part of my application functionality is to automatically fill gmail message subject, text, recipients and attach a photo.

    Your code has nothing specific to do with Gmail. There are many email clients for Android, and not everybody uses Gmail.

    How can I disable saving a draft before starting intent from my application?

    Write your own email client, rather than delegating to an existing email client. Otherwise, the decision of what goes on inside that email client is up to the user and the developers of that email client, not you.