2012-08-08 184 views
1

我想发送附件的邮件,我已经编写了代码,这是工作正常,但在这里我写了文件名,我想附加在程序中,我不想要像这样,我希望它是由用户从SD卡中选择。如何做到这一点。将附件添加到电子邮件

public class DemoVoiceActivity extends Activity { 
     EditText txtTo,mSubject,mMessageBody,attachment; 
     String strSubject,strMessageBody; 
     /** Called when the activity is first created. */ 
     @Override 
     public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.main); 
      txtTo = (EditText)findViewById(R.id.to); 

     mSubject = (EditText)findViewById(R.id.subject); 
     mMessageBody = (EditText)findViewById(R.id.message_content); 
     attachment=(EditText)findViewById(R.id.attachment); 

     String[] strTo = {txtTo.getText().toString()}; 

     strSubject = mSubject.getText().toString(); 
     strMessageBody = mMessageBody.getText().toString(); 
     Intent objIntent = new Intent(android.content.Intent.ACTION_SEND); 
     objIntent.putExtra(android.content.Intent.EXTRA_EMAIL, strTo); 

     objIntent.setType("plain/text"); objIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, strSubject); 
     objIntent.putExtra(android.content.Intent.EXTRA_TEXT, "MESSAGE"); objIntent.putExtra(android.content.Intent.EXTRA_STREAM,Uri.parse("file://"+Environment.getExternalStorageDirectory()+"/q.mp4")); 
     startActivity(objIntent); 
     finish(); 
    } 
} 

回答

1

退房这个答案 https://stackoverflow.com/a/7857102/975959

他provied一个简单的文件选择开源库。 然后您可以在onFileSelect()方法中获取文件路径并将其添加到您的objIntent

他还提供了自己实现它的方法,如果你愿意的话。

相关问题