Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify Action-and-Uri for Email intent, var args for addresses #7

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 4 additions & 20 deletions library/src/main/java/com/marvinlabs/intents/EmailIntents.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,8 @@ public class EmailIntents {
* @param body The body of the email (or null if not specified)
* @return the intent
*/
public static Intent newEmailIntent(String address, String subject, String body) {
return newEmailIntent(address, subject, body, null);
}

/**
* Create an intent to send an email with an attachment to a single recipient
*
* @param address The recipient address (or null if not specified)
* @param subject The subject of the email (or null if not specified)
* @param body The body of the email (or null if not specified)
* @param attachment The URI of a file to attach to the email. Note that the URI must point to a location the email
* application is allowed to read and has permissions to access.
* @return the intent
*/
public static Intent newEmailIntent(String address, String subject, String body, Uri attachment) {
return newEmailIntent(address == null ? null : new String[]{address}, subject, body, attachment);
public static Intent newEmailIntent(String subject, String body, String address) {
return newEmailIntent(subject, body, null, address);
}

/**
Expand All @@ -62,16 +48,14 @@ public static Intent newEmailIntent(String address, String subject, String body,
* application is allowed to read and has permissions to access.
* @return the intent
*/
public static Intent newEmailIntent(String[] addresses, String subject, String body, Uri attachment) {
Intent intent = new Intent(Intent.ACTION_SEND);
public static Intent newEmailIntent(String subject, String body, Uri attachment, String... addresses) {
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:"));
if (addresses != null) intent.putExtra(Intent.EXTRA_EMAIL, addresses);
if (body != null) intent.putExtra(Intent.EXTRA_TEXT, body);
if (subject != null) intent.putExtra(Intent.EXTRA_SUBJECT, subject);
if (attachment != null) intent.putExtra(Intent.EXTRA_STREAM, attachment);
intent.setType(MIME_TYPE_EMAIL);

return intent;
}

private static final String MIME_TYPE_EMAIL = "message/rfc822";
}