user1522869
user1522869

Reputation: 109

To add the attachment to email

I am trying to send the mail with attachment and I have writeen code for that which is working fine, but here I have written the file name which i want to attach in the program,I dont want like this I want it to be choose by the user from the sdcard.How to do it.

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

Upvotes: 1

Views: 126

Answers (1)

La bla bla
La bla bla

Reputation: 8718

Check out this answer https://stackoverflow.com/a/7857102/975959

He provied a simple file chooser open source library. You can then in the onFileSelect() method, get the file path and add it to your objIntent.

He also provides way of implementing it yourself, if you wish to do so.

Upvotes: 1

Related Questions