从Android中的Intent Filter获取电子邮件地址

时间:2014-08-17 00:38:25

标签: android intentfilter

如何通过android中的intent-filter获取电子邮件? 目前我尝试了这个,我可以获得Action SEND,但Extra_EMail为null。

    Intent intent = getIntent();
    String action = intent.getAction();
    String type = intent.getType();


    String sharedText = intent.getStringExtra(Intent.EXTRA_EMAIL);
    if (sharedText != null) {
        Toast.makeText(getApplicationContext(), sharedText,
                Toast.LENGTH_LONG).show();

        mEdit.setText(sharedText);
    }

2 个答案:

答案 0 :(得分:0)

只有当您将收件人作为字符串数组

传递时,它才会起作用

尝试这样:

emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
                      new String[] { "someone@gmail.com" });

答案 1 :(得分:0)

以下是我发送电子邮件的帮助函数:

public static Intent email(Context context, String[] addresses, String subject, String body, Uri attachment) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("message/rfc822");
    if (addresses != null)
        intent.putExtra(Intent.EXTRA_EMAIL, addresses);
    if (body != null)
        intent.putExtra(Intent.EXTRA_TEXT, body);
    if (subject != null)
        intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    if (attachment != null)
        intent.putExtra(Intent.EXTRA_STREAM, attachment);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    return intent;
}

您可以在Activity中使用它:

startActivity(email(this, new String [] {"abc@def.com", "Subject of email", "Message inside email", null));