gpt4 book ai didi

java - 我们如何动态设置 From email 从应用程序传递电子邮件 Intent

转载 作者:行者123 更新时间:2023-12-02 02:33:44 25 4
gpt4 key购买 nike

我想在我的应用程序中通过电子邮件 Intent 发送文件。但我想根据我的选择通过代码设置电子邮件 FROM id,而不是默认在我的设备中登录 gmail。Android 代码可以吗?

public void sendEmail() {
try {
Uri photoURI = FileProvider.getUriForFile(UserDetails.this, getApplicationContext().getPackageName() + ".provider", jsonFile);
String email = user.getEmail();
String subject = "User Export Data";
String message = "For getting the better understanding.Please open this json file with the json viewer tools.";
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{email});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
if (jsonFile != null) {
emailIntent.putExtra(Intent.EXTRA_STREAM, photoURI);
}
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
this.startActivity(emailIntent);
// this.startActivity(Intent.createChooser(emailIntent, "Sending email..."));
} catch (Throwable t) {
Toast.makeText(this, "Request failed try again: " + t.toString(), Toast.LENGTH_LONG).show();
}
}

最佳答案

试试这个

this.startActivity(new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:to@gmail.com")));

final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/plain");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String\[\]{ "serveroverloadofficial@gmail.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Hello There");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Add Message here");


emailIntent.setType("message/rfc822");

try {
startActivity(Intent.createChooser(emailIntent,
"Send email using..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(getActivity(),
"No email clients installed.",
Toast.LENGTH_SHORT).show();
}

}
});

关于java - 我们如何动态设置 From email 从应用程序传递电子邮件 Intent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57217246/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com