我只是想通过我的应用程序打开Gmail应用程序,并想通过我的应用程序设置电子邮件,主题和消息。
我已经尝试过GmailService,但它不支持密件抄送或cc电子邮件。 链接:https://github.com/yesidlazaro/GmailBackground
BackgroundMail.newBuilder(this)
.withUsername("username@gmail.com")
.withPassword("password12345")
.withMailto("toemail@gmail.com")
.withType(BackgroundMail.TYPE_PLAIN)
.withSubject("this is the subject")
.withBody("this is the body")
.withOnSuccessCallback(new BackgroundMail.OnSuccessCallback() {
@Override
public void onSuccess() {
//do some magic
}
}).withOnFailCallback(new BackgroundMail.OnFailCallback() {
@Override
public void onFail() {
//do some magic
}
}).send();
我想使用密件抄送和抄送功能以及附件,主题和消息。
答案 0 :(得分:4)
通过Intent打开Gmail
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("abc@gmail.com"));
intent.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");
intent.putExtra(Intent.EXTRA_CC, new String[]{"xyz@gmail.com"});
intent.putExtra(Intent.EXTRA_BCC, new String[]{"pqr@gmail.com"});
intent.putExtra(Intent.EXTRA_SUBJECT, "your subject goes here...");
intent.putExtra(Intent.EXTRA_TEXT, "Your message content goes here...");
startActivity(intent);
只需在意图参数中传递EXTRA_CC
和EXTRA_BCC
答案 1 :(得分:1)
//对于任何应用程序的电子邮件
Intent email= new Intent(Intent.ACTION_SENDTO);
email.setData(Uri.parse("mailto:your.eamil@gmail.com"));
email.putExtra(Intent.EXTRA_SUBJECT, "Subject");
email.putExtra(Intent.EXTRA_TEXT, "My Email message");
startActivity(email);
答案 2 :(得分:0)
我正在使用它来启动gmail应用。
val intent: Intent? = activity.packageManager.getLaunchIntentForPackage("com.google.android.gm")
if (intent != null) {
startActivity(intent)
}
else{
showToast("Sorry...You don't have gmail app")
}
答案 3 :(得分:0)
//这是用gmail打开的
Intent i = new Intent(Intent.ACTION_SENDTO);
i.setType("text/plain");
i.setData(Uri.parse("mailto:"));
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"recipient@gmail.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "Mail Subject");
i.putExtra(Intent.EXTRA_TEXT , "massage");
i.setPackage("com.google.android.gm");
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(AnotherActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
答案 4 :(得分:-1)
我正在使用这个
Intent mailClient = new Intent(Intent.ACTION_VIEW);
mailClient.setClassName("com.google.android.gm", "com.google.android.gm.ConversationListActivity");
startActivity(mailClient);
您也可以尝试
final Intent intent = new Intent(Intent.ACTION_VIEW)
.setType("plain/text")
.setData(Uri.parse("test@gmail.com"))
.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail")
.putExtra(Intent.EXTRA_EMAIL, new String[]{"test@gmail.com"})
.putExtra(Intent.EXTRA_SUBJECT, "test")
.putExtra(Intent.EXTRA_TEXT, "hello. this is a message sent from my demo app :-)");
startActivity(intent);
用于大量电子邮件:
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "test@gmail.com" });
对于单个电子邮件:
intent.setData(Uri.parse("test@gmail.com"));
答案 5 :(得分:-1)
//这是针对Gmail应用的
Intent email= new Intent(Intent.ACTION_VIEW);
email.setType("message/rfc822")
.setData(Uri.parse("mailto:your.email@gmail.com"))
.putExtra(Intent.EXTRA_EMAIL, "your.email@gmail.com")
.putExtra(Intent.EXTRA_SUBJECT, "Subject")
.putExtra(Intent.EXTRA_TEXT, "My Email message")
.setPackage("com.google.android.gm");
startActivity(email);