wir*_*bly 1 android android-intent
如果不拨打特定的包裹,这是否可行?我已经找到了无数通过意图发送电子邮件的例子,但是我无法通过按下按钮来打开设备上的默认电子邮件客户端(如果用户有多个客户端,最好使用选择器对话框).
小智 15
没有默认/简单的方法来做到这一点.这段代码对我有用.它打开一个选择器,所有电子邮件应用程序都注册到设备并直接进入收件箱:
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);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3639 次 |
| 最近记录: |