无法使用邮件发送多个附件

时间:2012-04-08 06:03:03

标签: android android-intent email-attachments

  

可能重复:
  Android multiple email attachments using Intent

我无法通过邮件发送多个附件。当我发送一个时,我就能成功。我不知道我做错了什么。我正在使用openFileOutput()在内部存储器中创建文件。

我创建了很多文本文件并且确定它们已经创建,因为我已经在文件资源管理器上验证了它们。我甚至可以记录文件的Uris,但其他东西出错了。这是我的代码。有人可以告诉我我做错了吗

    String eol = System.getProperty("line.separator");
    ArrayList<Uri> paths = new ArrayList<Uri>();
    FileOutputStream ffff;
    for(int j=mChecked.size()-1;j>=0;j--)
    {

        if(mChecked.get(j))
        {
            String attachementfilename = "chat"+j+".txt"; 

            try {
                ffff = mContext.openFileOutput(attachementfilename, Context.MODE_WORLD_READABLE);
                OutputStreamWriter osw = new OutputStreamWriter(ffff);
                String[] chatsforforwarding;
                chatsforforwarding = chats[j].split(delimiter);
                for(String s:chatsforforwarding)
                {
                    osw.write(s + eol);
                }
                osw.flush();
                osw.close();
                /*File fileIn = new File("mContext.getFileStreamPath(attachementfilename)");
                Uri u = Uri.fromFile(fileIn);
                paths.add(u);*/

                paths.add(Uri.fromFile(mContext.getFileStreamPath(attachementfilename)));

            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }


        }

    }

    for(Uri u:paths)
    {
        Log.d("path is:", String.valueOf(u));
    }

    Intent emailIntent;
    if(paths.size() == 1)
    {
          emailIntent = new Intent(android.content.Intent.ACTION_SEND);
        emailIntent.putExtra(Intent.EXTRA_STREAM, paths.get(0));
        emailIntent.setType("text/plain");
        //emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"talluridorababu@gmail.com"});
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, new String[]{"saved text from BlueToothChat"});
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, new String[]{"sample body"});
        //emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(mContext.getFileStreamPath("chat.txt")));

        mContext.startActivity(Intent.createChooser(emailIntent, "sending mail....."));

    }
    else if(paths.size()>1)
    {
        emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
        emailIntent.setType("text/plain");
        emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"talluridorababu@gmail.com"});
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, new String[]{"saved text from BlueToothChat"});
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, new String[]{"sample body"});
        //emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(mContext.getFileStreamPath("chat.txt")));
        emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, paths);
        /*for(Uri u : paths)
        {
            emailIntent.putExtra(Intent.EXTRA_STREAM, u);
        }*/
        mContext.startActivity(Intent.createChooser(emailIntent, "sending mail....."));

    }

0 个答案:

没有答案