Android set mail intent using url that includes subject

To set a mail intent in Android using a URL that includes the subject, you can use the following approach:

  1. Create a Uri object with the mailto scheme and the URL that includes the subject.
  2. Use the Intent constructor to create a new Intent object with the ACTION_SENDTO action and the Uri object as the data.
  3. Set the TYPE_EMAIL type on the Intent object to indicate that it's an email intent.
  4. Optionally, you can set the EXTRA_SUBJECT extra on the Intent object to specify the subject of the email.

Here's some sample code:

String url = "mailto:[email protected]?subject=Hello%20World!";
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_SUBJECT, "Hello World!");
startActivity(Intent.createChooser(intent, "Send email"));

In this example, the url variable contains the mailto URL with the subject included. The Uri object is created using the Uri.parse() method, and then passed to the Intent constructor along with the ACTION_SENDTO action.

The setType() method is used to set the type of the intent to message/rfc822, which indicates that it's an email intent.

The putExtra() method is used to set the EXTRA_SUBJECT extra on the intent, which specifies the subject of the email.

Finally, the startActivity() method is used to start the activity chooser, which will allow the user to select an email app to send the email.

Note that the EXTRA_SUBJECT extra is optional, and you can omit it if you don't want to specify a subject for the email.