【问题标题】:Android send email with text and imagesAndroid 发送带有文本和图像的电子邮件
【发布时间】:2011-12-27 22:26:21
【问题描述】:

我希望用户能够从我的 android 应用程序中发送电子邮件,所以我有

    Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, emailaddress);
    emailIntent.setType("plain/text");
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,message);
    startActivity(emailIntent);

但如果我还想将 2 张 .png 图片附加到这封电子邮件,我不知道该怎么做。

谢谢,

【问题讨论】:

    标签: android image email attachment


    【解决方案1】:

    试试这个。 但对我来说,它只适用于真实设备。

        Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    
        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, emailaddress);
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
        emailIntent.setType("image/png");
    
        ArrayList<Uri> uris = new ArrayList<Uri>();
    
        uris.add(Uri.parse("android.resource://" + getPackageName() + "/" + R.drawable.file1));
        uris.add(Uri.parse("android.resource://" + getPackageName() + "/" + R.drawable.file2));
    
        emailIntent.putExtra(Intent.EXTRA_STREAM, uris));
    
        startActivity(emailIntent);
    

    【讨论】:

    • 代码有两个错误。对于多个附件,应使用Intent.ACTION_SEND_MULTIPLE。第 12 行多了一个右括号,应该是 .putExtra(Intent.EXTRA_STREAM, uris);
    【解决方案2】:

    试试这个:

    Intent iShare;
    iShare = new Intent(Intent.ACTION_SEND);
    iShare.setType("image/png");
    
    //below you trying to send the images path it always doens have to be a
    //image in the drawable u can get the captured image or in the gallery :)
    iShare.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+fn.getPath()));
    i.putExtra(Intent.EXTRA_TEXT, "Username: " + usernames + "\nClinic Number: " + clnumber + "\nClinic Name: " + clname + "\nBranch: " + spnnr);
    startActivity(Intent.createChooser(iShare, "Share"));
    
    try {
        startActivity(Intent.createChooser(ishare, "Send mail..."));
    } catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(secondpage.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
    }
    

    【讨论】:

      猜你喜欢
      • 2013-06-01
      • 1970-01-01
      • 2015-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-27
      • 2015-07-29
      相关资源
      最近更新 更多