2

Hi friends,

I need to send zip file as attachment to email. I have tried using code below. However, I receive email message without the attachment. What am I doing wrong?

  public class MainActivity extends Activity {
   Button email;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    email=(Button)findViewById(R.id.button1);
    email.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {
            // TODO Auto-generated method stub

            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"radha@impressol.com"});
            intent.putExtra(Intent.EXTRA_SUBJECT, "Email Subject");
            intent.putExtra(Intent.EXTRA_TEXT, "Email Message");
            intent.setType("application/zip");
            intent.putExtra(Intent.EXTRA_STREAM,        Uri.parse("file://+/sdcard/zipname.zip"));
            startActivity(Intent.createChooser(intent, "Send Email"));

        }
    });
}

  }
PSS
  • 5,561
  • 5
  • 28
  • 30
user2401554
  • 121
  • 4
  • 19

1 Answers1

3

In your case remove the "+" from Uri string.

P.S. it'll also work without Uri protocol, like (Environment.getExternalStorageDirectory()+"/zipname.zip");

IronBlossom
  • 3,898
  • 3
  • 35
  • 42