Skip to content Skip to sidebar Skip to footer

Can Not Attach Pdf Into Mail In Android

I am trying to create a pdf and send via email. Now I have sucessfully completed the pdf generation. When I try to attach the pdf into mail and send, I am getting error. I am tryin

Solution 1:

So Finlay I got the solution(Tips given by @CommonsWare)..

sendMail(Uri.fromFile(emailFilePath));

Send email Method:-

privatevoidsendMail(Uri URI) {
        try {

            Stringemail= emailFromDB;

            Stringsubject="Report For the day " + getDateTime();

            Stringmessage="Report For the day " + getDateTime();

            finalIntentemailIntent=newIntent(android.content.Intent.ACTION_SEND);
            emailIntent.setType("application/pdf");
            emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,newString[] { email });
            emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,subject);

            if (URI != null) {
                emailIntent.putExtra(Intent.EXTRA_STREAM, URI);
            }

            emailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            this.startActivity(Intent.createChooser(emailIntent,"Sending email..."));

        } catch (Throwable t) {

            Toast.makeText(this,

            "Request failed try again: " + t.toString(),

            Toast.LENGTH_LONG).show();

        }

    }

Here I have removed emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message); and get the URI like Uri.fromFile(emailFilePath). This solved my problem. Thanks to @CommonnsWare..!!!

Post a Comment for "Can Not Attach Pdf Into Mail In Android"