-1

After making some research in google and stackoverflow, I learned that I'm able to send different content for different apps in Android like the one here.

However, I encountered some issues.

  1. I want to send a HTML email if any mail client is chosen (phone default mail client, Gmail Apps, Outlook Apps and others). In the link above, I need to specific each mail app individually which I want to avoid from.

  2. When I try to send the HTML email through GMAIL app. It is not formatted like it supposed to.

edwin
  • 1,152
  • 1
  • 13
  • 27

1 Answers1

0

I want to send a HTML email if any mail client is chosen

There is no such way to query about the activities which are used to send only email, Intent.ACTION_SEND will get all the apps who are able to send the MIME_TYPE you define.

For instance, if you use plain/text as MIME_TYPE, all the client that can share plain/text will be returned. It is upto user - which app they want to share with. However, you can compare the package name to make sure which app is selected.

Suppose, you want to check if the gmail client is selected,

// Query about app that can send `text/plain`
final Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_TEXT,"text");

final List<ResolveInfo> activities = getPackageManager().queryIntentActivities (i, 0);

// Check if gmail is clicked, when the `chooser` item is clicked,
ResolveInfo info = activities.get(position);
if (info.activityInfo.packageName.contains("com.google.android.gm")) {
    // Gmail was chosen
}

When I try to send the HTML email through GMAIL app. It is not formatted like it supposed to.

Html does not support all the Html tags, You need to write your own tag handler to do so. Check out this link to see what tags are supported by Html.

Paresh P.
  • 6,677
  • 1
  • 14
  • 26