gpt4 book ai didi

android - 如何将电子邮件客户端直接启动到收件箱 View ?

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

这甚至可以在不调用特定包的情况下实现吗?我发现了无数通过 Intent 发送电子邮件的例子,但我找不到任何关于通过按下按钮在设备上简单地打开默认电子邮件客户端的例子(如果用户有多个客户端,最好使用选择器对话框)。

最佳答案

没有默认/简单的方法可以做到这一点。这段代码对我有用。它会打开一个选择器,其中包含已注册到设备并直接进入收件箱的所有电子邮件应用程序:

    Intent emailIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("mailto:"));
PackageManager pm = getPackageManager();

List<ResolveInfo> resInfo = pm.queryIntentActivities(emailIntent, 0);
if (resInfo.size() > 0) {
ResolveInfo ri = resInfo.get(0);
// First create an intent with only the package name of the first registered email app
// and build a picked based on it
Intent intentChooser = pm.getLaunchIntentForPackage(ri.activityInfo.packageName);
Intent openInChooser =
Intent.createChooser(intentChooser,
getString(R.string.user_reg_email_client_chooser_title));

// Then create a list of LabeledIntent for the rest of the registered email apps
List<LabeledIntent> intentList = new ArrayList<LabeledIntent>();
for (int i = 1; i < resInfo.size(); i++) {
// Extract the label and repackage it in a LabeledIntent
ri = resInfo.get(i);
String packageName = ri.activityInfo.packageName;
Intent intent = pm.getLaunchIntentForPackage(packageName);
intentList.add(new LabeledIntent(intent, packageName, ri.loadLabel(pm), ri.icon));
}

LabeledIntent[] extraIntents = intentList.toArray(new LabeledIntent[intentList.size()]);
// Add the rest of the email apps to the picker selection
openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
startActivity(openInChooser);
}

关于android - 如何将电子邮件客户端直接启动到收件箱 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3489068/

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