gpt4 book ai didi

Android Intent.createChooser 不适用于 Intent.ACTION_SEND

转载 作者:太空狗 更新时间:2023-10-29 13:30:44 26 4
gpt4 key购买 nike

我有一个 android 应用程序,我通过自定义 Adapter 将办公室位置加载到 ListView 中。

在每个 ListViewItem 中,我有一个 ImageView,它是一个电子邮件图标,我已将自定义 OnClickListener 绑定(bind)到 ImageView 应该允许用户创建电子邮件以发送到办公地点。

我希望用户能够从他们设备上的电子邮件应用程序中进行选择,所以我在我的自定义 OnClickListener 中使用了 Intent.CreateChooser() 就像这样:

    private class EmailOnClickListener implements OnClickListener {
private Context context;
private String email;

public EmailOnClickListener(Context context, String email) {
this.context = context;
this.email = email;
}

@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("message/rfc822");
intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {email});
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Test Subject");

context.startActivity(Intent.createChooser(intent, "Send mail..."));
}
}

我已经通过我的自定义 Adapter 绑定(bind)了我的自定义 OnClickListener,如下所示:

    ImageView email = (ImageView) v.findViewById(R.id.btnEmail);
email.setOnClickListener(new EmailOnClickListener(context, contact.getEmail()));

我目前正在 HTC Desire HD 上测试它,它是 Android 2.3,即使我的设备上有 Gmail 和默认邮件,当我点击电子邮件图标时,它没有显示选择器,但它只是加载直接进入 Gmail。

为什么选择器不显示?

最佳答案

我从这个问题中找到了答案(寻找哆啦A梦的答案)Send Email Intent

为了快速引用,我已将 onClick 方法中的代码更改为以下内容:

Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", email, null));
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Test Subject");

context.startActivity(Intent.createChooser(intent, "Send mail..."));

关于Android Intent.createChooser 不适用于 Intent.ACTION_SEND,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15803625/

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