I want to open Gmail with a preformatted email. I am using this code:
public static void sendEmail(Context context, String receiverAddress, String title, String body) {
Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { receiverAddress });
emailIntent.putExtra(Intent.EXTRA_SUBJECT, title);
if (body != null) {
emailIntent.putExtra(Intent.EXTRA_TEXT, body);
}
if (emailIntent.resolveActivity(context.getPackageManager()) != null) {
context.startActivity(emailIntent);
}
}
However it works only if I add this intent-filter
to the manifest file of my app:
<intent-filter>
<action android:name="android.intent.action.SENDTO" />
<data android:scheme="mailto" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
By doing this, it shows me an app selector with two apps: my app and Gmail.
However I don't want my app to be the receiver of this intent. I just want this intent received by Gmail (and other email clients).
But if I don't add that intent-filter
, nothing happens.
What am I doing wrong?