Search code examples
androidandroid-intentemail-client

Attachment sent through email is of 0KB size


I am developing an application in which I have to send an image through email. I succeeded in sending email, but the attachment sent is of 0KB size. I am not getting what is the problem. Below, I am posting my code.

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class EtestActivity extends Activity {
/** Called when the activity is first created. */
Button email;
Intent in;
private static final String TAG = "EmailLauncherActivity";
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    email = (Button)findViewById(R.id.email);
    email.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            try {
                in = new Intent(Intent.ACTION_SEND);
                in.setType("image/jpeg");
                in.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/android.jpg"));

                startActivity(Intent.createChooser(in, "Email..."));
            } catch (Exception e) {
                Log.e(TAG, "email sending failed", e);
            }//catch
        }//onClick
    });
}//onCreate
}//class

Solution

  • I also face the same problem which is solved by changing MIME type.

    Try this in.setType("image/jpg");