//Intent to gmail
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.setData(Uri.parse("mailto:"));
//how can ? add this part
sendIntent.putExtra(Intent.EXTRA_EMAIL,fromEmail);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Feedback");
sendIntent.putExtra(Intent.EXTRA_TEXT, emailBody);
sendIntent.setType("text/plain");
try {
Intent shareIntent = Intent.createChooser(sendIntent, "Feedback");
startActivity(shareIntent);
Log.i("Finished sending email...", "");
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MainActivity.this, "There is no email client installed.", Toast.LENGTH_SHORT).show();
}
發件人作業正常,但我無法制作收件人。你能幫助我嗎?
uj5u.com熱心網友回復:
我不知道具體的設計是怎樣的。我也不確定你從哪里得到收件人的電子郵件,但也許這段代碼對你有用。
public void contact() {
final Intent send = new Intent(Intent.ACTION_SENDTO);
final String email = "[email protected]";
final String subject = "subject";
final String body = "body...";
final String uriText = "mailto:" Uri.encode(email)
"?subject=" Uri.encode(subject)
"&body=" Uri.encode(body);
final Uri uri = Uri.parse(uriText);
send.setData(uri);
startActivity(Intent.createChooser(send, getString(R.string.settings_email_chooser)));
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/461053.html
