英文:
send Email through Android Intent
问题
我尝试通过Android Intent发送电子邮件,使用以下代码:
Intent sendIntent = new Intent();
sendIntent.putExtra(Intent.EXTRA_TEXT, EmailContent);
sendIntent.putExtra(Intent.EXTRA_EMAIL, RecipientName);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
sendIntent.setType("message/rfc822");
sendIntent.setAction(Intent.ACTION_SEND);
Intent chooser = Intent.createChooser(sendIntent, chooser_title);
if (sendIntent.resolveActivity(getPackageManager()) != null) {
startActivity(chooser);
}
在电子邮件应用程序中,收件人详细信息没有更新,而其他详细信息,如主题和正文,都已根据我的输入更新。请问是否可以建议如何解决此问题。
英文:
I have tried to send Email through Android Intent by using below code
Intent sendIntent = new Intent();
sendIntent.putExtra(Intent.EXTRA_TEXT, EmailContent);
sendIntent.putExtra(Intent.EXTRA_EMAIL, RecipientName );
sendIntent.putExtra(Intent.EXTRA_SUBJECT , subject );
sendIntent.setType("message/rfc822");
sendIntent.setAction(Intent.ACTION_SEND);
Intent chooser = Intent.createChooser(sendIntent , chooser_title );
if (sendIntent.resolveActivity(getPackageManager()) != null) {
startActivity(chooser);
}
In the email app the recipient details are not getting update whereas all the other details such as subject, body is getting updated with my input . Could you please suggest what needs to be done to resolve this .
答案1
得分: 0
尝试将EXTRA_EMAIL作为字符串数组传递。
英文:
Try to pass the EXTRA_EMAIL as string array.
答案2
得分: 0
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
"mailto","abc@gmail.com", null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Body");
startActivity(Intent.createChooser(emailIntent, "Send email..."));
英文:
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
"mailto","abc@gmail.com", null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Body");
startActivity(Intent.createChooser(emailIntent, "Send email..."));
答案3
得分: 0
尝试使用以下内容:
创建用于收件人的字符串资源:-
<string-array name="receipients">
<item>mgf@kgf.co</item>
<item>sdf@kgf.co</item>
</string-array>
并使用以下意图:
Intent gmailIntent = new Intent(Intent.ACTION_SEND);
gmailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
gmailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, resources.getStringArray(R.array.receipients));
gmailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
gmailIntent.putExtra(android.content.Intent.EXTRA_TEXT, EmailContent);
gmailIntent.setType("message/rfc822");
gmailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
final PackageManager pm = context.getApplicationContext().getPackageManager();
final List<ResolveInfo> matches = pm.queryIntentActivities(gmailIntent, 0);
ResolveInfo best = null;
for (final ResolveInfo info : matches)
if (info.activityInfo.packageName.endsWith(".gm") ||
info.activityInfo.name.toLowerCase().contains("gmail")) best = info;
if (best != null)
gmailIntent.setClassName(best.activityInfo.packageName, best.activityInfo.name);
try {
startActivity(gmailIntent);
} catch (ActivityNotFoundException ex) {
Toast.makeText(context.getApplicationContext(), getString(R.string.you_do_not_have_gmail_installed), Toast.LENGTH_SHORT).show();
}
英文:
Try using this:-
Create String resource for recipients:-
<string-array name="receipients">
<item>mgf@kgf.co</item>
<item>sdf@kgf.co</item>
</string-array>
and use this intent
Intent gmailIntent = new Intent(Intent.ACTION_SEND);
gmailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
gmailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, resources.getStringArray(R.array.receipients));
gmailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,subject);
gmailIntent.putExtra(android.content.Intent.EXTRA_TEXT, EmailContent);
gmailIntent.setType("message/rfc822");
gmailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
final PackageManager pm = context.getApplicationContext().getPackageManager();
final List<ResolveInfo> matches = pm.queryIntentActivities(gmailIntent, 0);
ResolveInfo best = null;
for (final ResolveInfo info : matches)
if (info.activityInfo.packageName.endsWith(".gm") ||
info.activityInfo.name.toLowerCase().contains("gmail")) best = info;
if (best != null)
gmailIntent.setClassName(best.activityInfo.packageName, best.activityInfo.name);
try {
startActivity(gmailIntent);
} catch (ActivityNotFoundException ex) {
Toast.makeText(context.getApplicationContext(), getString(R.string.you_do_not_have_gmail_installed), Toast.LENGTH_SHORT).show();
}
专注分享java语言的经验与见解,让所有开发者获益!
评论