Intent android error

1

I have a query I am creating a intent to send in email with a pdf attached but when the gmail is launched, everything is set correctly except the destination email field.

My code is the following for Intent :

            String s = mEmailCliente;


            String[] mailto = new String[1];
            mailto[0]=s;
            Uri uri = Uri.fromFile(new File(String.valueOf(pdfFile)));

            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setData(Uri.parse("mailto:")); // only email apps should handle this
            intent.putExtra(Intent.EXTRA_SUBJECT, "Su Factura");
            intent.putExtra(android.content.Intent.EXTRA_TEXT, "Buenas estimad@: a continuación se le adjunta su factura número F" + no_factura);
            intent.setType("application/pdf");
            intent.putExtra(Intent.EXTRA_EMAIL, mailto);


            intent.putExtra(Intent.EXTRA_STREAM, uri);
            startActivity(Intent.createChooser(intent, "Compartir vía: "));

Someone has an idea because it does not take the value of the variable called s , however if the array mailto specified a mail in quotes this if it takes it correctly. Greetings

    
asked by Yasnier Perdigon Lorenzo 30.06.2018 в 00:21
source

2 answers

1

Are you sure that mEmailCliente has value?

Try this:

        Uri uri = Uri.fromFile(new File(String.valueOf(pdfFile)));

        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setData(Uri.parse("mailto:")); // only email apps should handle this
        intent.putExtra(Intent.EXTRA_SUBJECT, "Su Factura");
        intent.putExtra(android.content.Intent.EXTRA_TEXT, "Buenas estimad@: a continuación se le adjunta su factura número F" + no_factura);
        intent.setType("application/pdf");
        intent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] { mEmailCliente });



        intent.putExtra(Intent.EXTRA_STREAM, uri);
        startActivity(Intent.createChooser(intent, "Compartir vía: "));'

I hope it serves you.

Greetings !!

    
answered by 30.06.2018 в 02:42
1

The problem you are presenting may be due to several reasons.

The first is that mEmailCliente does not have an email or that it has no value.

The second is that if you are using Gmail as a client, you may commonly experience that the recipient account is not added, it is probably a problem of the same client when trying to add attachments.

I suggest you define the type ( intent.setType("application/pdf"); ), you must define the EXTRAS, it is for this reason that you are probably not taking the email from the recipient or recipient.

        Uri uri = Uri.fromFile(new File(String.valueOf(pdfFile)));

        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setData(Uri.parse("mailto:")); // only email apps should handle this
        intent.putExtra(Intent.EXTRA_SUBJECT, "Su Factura");
        intent.putExtra(android.content.Intent.EXTRA_TEXT, "Buenas estimad@: a continuación se le adjunta su factura número F" + no_factura);        
        intent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] { mEmailCliente });



        intent.putExtra(Intent.EXTRA_STREAM, uri);

        intent.setType("application/pdf"); //***

        startActivity(Intent.createChooser(intent, "Compartir vía: "));'
    
answered by 30.06.2018 в 01:27