0

我尝试了以下发送带有附件的电子邮件的代码。它在尝试发送时确实显示附件,但问题是它只发送带有主题和正文但没有附件的电子邮件。我会感谢你的帮助

 emailButton = (Button) findViewById(R.id.emailButton);

 textTo = (EditText) findViewById(R.id.txtenterserial);
 textSubject = (EditText) findViewById(R.id.txtenterseri);
 textMessage = (EditText) findViewById(R.id.txtenters);

 emailButton.setOnClickListener(new OnClickListener() {

     @Override
     public void onClick(View v) {

         String to = textTo.getText().toString();
         String subject = textSubject.getText().toString();
         String message = textMessage.getText().toString();

         Intent i = new Intent(Intent.ACTION_SEND);
         i.setType("text/plain");
         File data = null;
         try {
             Date dateVal = new Date();
             String filename = dateVal.toString();
             data = File.createTempFile("Report", ".csv");
             Log.d("vvvvvv", data.toString());
              FileWriter out = (FileWriter) GenerateCsv.generateCsvFile(data, "Name,Data1");
             //Log.d("SSSSHOOOOW", out.toString());
             i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(data));
             i.putExtra(Intent.EXTRA_EMAIL, new String[] { to });
             i.putExtra(Intent.EXTRA_SUBJECT, subject);
             i.putExtra(Intent.EXTRA_TEXT, message);
             startActivity(Intent.createChooser(i, "E-mail"));
          } catch (IOException e) {
                e.printStackTrace();
          }
     }
 });


 public static  class GenerateCsv {
     public static  FileWriter generateCsvFile(File sFileName,String fileContent) {

         FileWriter writer = null;

         try {
             writer = new FileWriter(sFileName);
             writer.append(fileContent);
             writer.flush();

         } catch (IOException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
         } finally {
              try {
                  writer.close();
              } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
              }
          }
          return writer;
     }
 }

这是 LogCat

01-20 22:07:26.998: E/Trace(8471): error opening trace file: No such file or directory (2)
01-20 22:07:27.929: D/gralloc_goldfish(8471): Emulator without GPU emulation detected.
01-20 22:07:46.538: D/vvvvvv(8471): /data/data/com.example.emailandroid/cache/Report1916903470.csv
01-20 22:07:46.998: D/dalvikvm(8471): GC_CONCURRENT freed 201K, 5% free 4318K/4544K, paused 78ms+82ms, total 292ms
01-20 22:07:47.458: I/Choreographer(8471): Skipped 94 frames!  The application may be doing too much work on its main thread.
01-20 22:07:51.828: W/IInputConnectionWrapper(8471): showStatusIcon on inactive InputConnection
01-20 22:07:52.718: I/Choreographer(8471): Skipped 58 frames!  The application may be doing too much work on its main thread.
01-20 22:09:40.928: I/Choreographer(8471): Skipped 33 frames!  The application may be doing too much work on its main thread.

请告诉我我哪里出错了。

4

1 回答 1

0

这可能是因为您的 gmail 应用程序无权从您的私有数据文件夹中读取。尝试将文件存储在外部存储中。

于 2013-02-01T14:03:48.360 回答