Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL,
new String[] { "email@example.com" });
intent.putExtra(Intent.EXTRA_SUBJECT, "subject here");
intent.putExtra(Intent.EXTRA_TEXT, "body text");
File root = Environment.getExternalStorageDirectory();
// File file = new File(root, filename);
if (!file.exists() || !file.canRead()) {
Toast.makeText(couponAlert, "Attachment Error",
Toast.LENGTH_SHORT).show();
// finish();
return;
}
Uri uri = Uri.fromFile(file);
;
intent.putExtra(Intent.EXTRA_STREAM, uri);
final PackageManager pm = couponAlert.getPackageManager();
final List<ResolveInfo> matches = pm.queryIntentActivities(
intent, 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)
intent.setClassName(best.activityInfo.packageName,
best.activityInfo.name);
couponAlert.startActivity(intent);
couponAlert.callFinish();
我想通过gmail邮寄,我是通过意图调用gmail应用程序,但在发送电子邮件后,它会回家并且我的应用程序关闭。 有一件事在这里。我称之为电子邮件意图的活动是Tabactivity的Child活动,我们的应用程序正在处理MainTAb活动,并且电子邮件功能用于其中一个活动。 请尽早回复