1

我正在尝试发送带有附件的邮件,并且我已经编写了运行良好的代码,但是在这里我已经写了我想在程序中附加的文件名,我不希望这样我希望它被选择来自 sdcard.How 的用户。

    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();
    }
}
4

1 回答 1

1

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

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

如果您愿意,他还提供了自己实施的方法。

于 2012-08-08T13:48:58.333 回答