0

我想在android中发送带有多个附件的电子邮件,我得到了解决方案,但现在的问题是我有2个文件,一个在SDCard中,另一个在android的本地目录中,即Drawable文件夹。我在发送电子邮件时完成了编码,它显示了两个附件,但我只收到一个存在于 SD 卡中的附件,我无法从内部文件夹(即可绘制)中获取附件。下面是我的代码,请帮我解决这个问题。

public class TransmitAgreement extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_transmit_agreement);

    String addressLine = gpsTracker.getAddressLine(this);
    String emailaddress = "myemail";
    String message = "Msg"
    String subject = "sbj";

    Intent emailIntent = new Intent(
            android.content.Intent.ACTION_SEND_MULTIPLE);
    emailIntent.setType("text/plain");
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
            new String[] { emailaddress });
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
    emailIntent.putExtra(Intent.EXTRA_TEXT, message);
    ArrayList<Uri> uris = new ArrayList<Uri>();
    // convert from paths to Android friendly Parcelable Uri's
    String[] filePaths = new String[] {
            "android.resource://com.example.freenup/" + R.drawable.freenup_app_agreement,
            "sdcard/saved_images/MyImage.png" };
    for (String file : filePaths) {
        File fileIn = new File(file);
        Uri u = Uri.fromFile(fileIn);
        uris.add(u);
    }
    emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
    startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.transmit_agreement, menu);
    return true;
}
}

我也尝试过其他解决方案,但遇到了同样的问题。我在电子邮件中只收到一个附件...

4

1 回答 1

2

我认为您不能不直接从可绘制文件夹发送附件

所以尝试这种方式

    try
            {
            Intent email = new Intent(Intent.ACTION_SEND_MULTIPLE);
            email.setType("plain/text");
            email.putExtra(Intent.EXTRA_EMAIL, new String[] {"email id"});
            email.putExtra(Intent.EXTRA_SUBJECT, "That one works");
            FileOutputStream outStream; 
            File file;

            Bitmap bm = BitmapFactory.decodeResource( getResources(), R.drawable.ic_launcher);
                    String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
            file = new File(extStorageDirectory, "ic_launcher.PNG");
            try {
                outStream = new FileOutputStream(file);
                bm.compress(Bitmap.CompressFormat.PNG, 100, outStream);
                outStream.flush();
                outStream.close();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }

            File[] f = new File[2];
            f[0] = new File("/mnt/ext_card/Download/test.jpg");
            f[1] = file;

            ArrayList<Uri> uris = new ArrayList<Uri>();

            for(int i=0;i<f.length;i++)

              {

                Uri u = Uri.fromFile(f[i]);
                uris.add(u);

              }

            email.putExtra(Intent.EXTRA_EMAIL, new String[] { "" });
            email.putExtra(Intent.EXTRA_SUBJECT, "My Subject");
            email.putExtra(Intent.EXTRA_TEXT, "");
            email.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
            startActivity(Intent.createChooser(email, "Choose an Email client :"));

            }

            catch (Exception e) {

                e.toString();

            }
于 2013-10-09T06:34:18.707 回答