【发布时间】:2015-03-01 17:34:40
【问题描述】:
我正在构建一个应用程序来处理与大学生的学术生活有关的任何事情,包括他的大学邮件帐户。
假设安装了我的应用的手机有两个或更多不同的 gmail 帐户集:
- “帐户 1” - “abcdef@gmail.com”
- “账户 2” - “123456@mydomain.com”
我知道要启动 gmail 应用程序,我可以使用以下代码:
public void showMailBox(View view){
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setType("plain/text");
sendIntent.setData(Uri.parse("test@gmail.com"));
sendIntent.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");
sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "test@gmail.com" });
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "test");
sendIntent.putExtra(Intent.EXTRA_TEXT, "hello");
startActivity(sendIntent);
}
我如何设置意图以启动 Gmail 或 Inbox,并将第二个帐户设置为发件人?
【问题讨论】:
-
“我知道要启动 gmail 应用程序,我可以使用此代码”——仅适用于某些版本的 Gmail 应用程序。一旦他们重构了他们的代码,你的代码就会崩溃。此外,
plain/text不是 MIME 类型。除此之外,Gmail 没有记录或支持的设备 API 来操作他们的应用程序。