添加附件?

时间:2013-12-01 10:16:52

标签: java android attachment

请帮助我,以下代码在eclipse上完美运行,但我想添加一个附件,我不知道如何或在哪里!?:

public class MainActivity extends Activity {

    @Override 
    public void onCreate(Bundle icicle) { 
      super.onCreate(icicle); 
      setContentView(R.layout.main); 

      Button addImage = (Button) findViewById(R.id.send_email); 
      addImage.setOnClickListener(new View.OnClickListener() { 

        public void onClick(View view) { 
             new SendEmailAsyncTask().execute();

        }
        class SendEmailAsyncTask extends AsyncTask <Void, Void, Boolean> {
          Mail m = new Mail("****@gmail.com", "Password");

          public SendEmailAsyncTask() {
              if (BuildConfig.DEBUG) Log.v(SendEmailAsyncTask.class.getName(), "SendEmailAsyncTask()");

              String[] toArr = {"****@gmail.com", "*****@gmail.com"}; 
              m.setTo(toArr); 
              m.setFrom("****@gmail.com"); 
              m.setSubject("Email from Android"); 
              m.setBody("Email body."); 
          } 

          @Override
          protected Boolean doInBackground(Void...params ) {
              if (BuildConfig.DEBUG) Log.v(SendEmailAsyncTask.class.getName(), "doInBackground()");
              try {
                // m.addAttachment("root/test.txt");
  

在这里添加它是否正确?顺便说一下,我试过了,但它没有用。

                   m.send();
                  return true;
              } catch (AuthenticationFailedException e) {
                  Log.e(SendEmailAsyncTask.class.getName(),"Bad account details");
                  e.printStackTrace();
                  return false;
              } catch (MessagingException e) {
                 // Log.e(SendEmailAsyncTask.class.getName(), m.getTo(null) + "failed");
                  e.printStackTrace();
                  return false;
              } catch (Exception e) {
                  e.printStackTrace();
                  Log.e("MailApp", "Could not send email", e);
                  return false;
              } 
          }
        }
      });
    }
}

0 个答案:

没有答案