【问题标题】:Get Email Address from Intent Filter in Android从 Android 中的意图过滤器获取电子邮件地址
【发布时间】:2014-08-17 00:38:25
【问题描述】:

如何获取通过 android 中的意图过滤器发送的电子邮件? 目前我试过这个,我可以得到 Action SEND,但是 Extra_EMail 是空的。

    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);
    }

【问题讨论】:

    标签: android intentfilter


    【解决方案1】:

    只有当你将接收者作为字符串数组传递时它才应该起作用

    试试这样:

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

    【讨论】:

      【解决方案2】:

      这是我发送电子邮件的辅助函数:

      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));
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-06-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多