gpt4 book ai didi

android - Intent.ACTION_SENDTO 显示两个选项,我只想显示一个

转载 作者:行者123 更新时间:2023-11-29 15:59:22 24 4
gpt4 key购买 nike

Intent.ACTION_SENDTO 中显示了两个选项,但我的客户要求删除 gmail 选项,但我没有找到出路请帮助我

  Intent emailIntent =
new Intent(Intent.ACTION_SENDTO,
Uri.fromParts( "mailto",userInput.getText().toString(), null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Press Release");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Please view this press release");
startActivity(Intent.createChooser(emailIntent,"Send mail using..."));

enter image description here

最佳答案

使用emailIntent.setPackage(电子邮件应用的 PackageName); 在调用 startActivity 之前。


您需要设置电子邮件客户端程序包名称,但在三星设备中 com.sec.android.email 是默认的内置邮件客户端,但在 HTC 中它是 com.htc.android.mail 等。因此,首先您需要过滤该应用程序,然后设置为 Intent 。我正在添加解决方案

Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
"mailto", userInput.getText().toString(), null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Press Release");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
"Please view this press release");

// Identify the package name of email client and set to intent
List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(emailIntent, 0);
if (!resInfo.isEmpty()) {
for (ResolveInfo info : resInfo) {
if (info.activityInfo.packageName.toLowerCase().contains(".android.email")
|| info.activityInfo.name.toLowerCase().contains(".android.email")) {
emailIntent.setPackage(info.activityInfo.packageName);
// And now call
startActivity(Intent.createChooser(emailIntent, "Send mail using..."));
}
}
}

你应该阅读 Android: How to get the native Email clients package name

关于android - Intent.ACTION_SENDTO 显示两个选项,我只想显示一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25602472/

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