Messaging and email intents in Android?

2019-03-02 03:27发布

问题:

I've searched Google for this, but have only found similar examples--not exactly what I need. I simply need to start messaging (SMS) and email intents from my app with their "to" fields already populated. So I need to send a number with the sms intent and an email address with the email intent. Any help would be appreciated.

回答1:

For the e-mail part :

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {"foo@bar.com"});

emailIntent.setType("text/plain");
startActivity(Intent.createChooser(emailIntent, "Send a mail ..."));


回答2:

from Only Email apps to resolve an Intent

   String recepientEmail = ""; // either set to destination email or leave empty
   Intent intent = new Intent(Intent.ACTION_SENDTO);
   intent.setData(Uri.parse("mailto:" + recepientEmail));
   startActivity(intent);

will filter out all non-email applications.