Skip to content Skip to sidebar Skip to footer

Error: Cannot Attach Empty File In Gmail App Using File Provider

I am trying to attach a pdf file in gmail app. I have read this and this (applied solution) I am trying as; public static void attachFile(Context ctx) { String TAG = 'Attach';

Solution 1:

Send the file in URI format like this:

Intent emailIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
        emailIntent.setData(Uri.parse("mailto:"));
        emailIntent.setType("application/image");
        emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
        emailIntent.putExtra(Intent.EXTRA_CC, CC);
ArrayList<Uri> uris = new ArrayList<>();
        //convert from paths to Android friendly Parcelable Uri's
        uris.add(frontImageUri);
        uris.add(backImageUri);
        emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
startActivity(Intent.createChooser(emailIntent, "Send mail..."));

Solution 2:

if it's ok To send Zip then try this way

StringfileNameStor_zip= Environment.getExternalStorageDirectory() + "/" + fileName + ".zip";

String[] path = { your 1st pdf  File Path, your 2nd pdf  File Path};

Compresscompress=newCompress(path, fileNameStor_zip);

compress.zip();


URI =  Uri.parse("file://" + fileNameStor_zip);

Provide your Gmail Intent

intent.putExtra(Intent.EXTRA_STREAM, URI);

Solution 3:

UricontentUri= FileProvider.getUriForFile(this, "com.mydomain.fileprovider", newFile);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
i.setData(contentUri);

Solution 4:

String filename="my_file.vcf"; 
Filefilelocation=newFile(Environment.getExternalStorageDirectory().getAbsolutePath(), filename);
Uripath= Uri.fromFile(filelocation); 
IntentemailIntent=newIntent(Intent.ACTION_SEND);
// set the type to 'email'
emailIntent .setType("vnd.android.cursor.dir/email");
String to[] = {"asd@gmail.com"};
emailIntent .putExtra(Intent.EXTRA_EMAIL, to);
// the attachment
emailIntent .putExtra(Intent.EXTRA_STREAM, path);
// the mail subject
emailIntent .putExtra(Intent.EXTRA_SUBJECT, "Subject");
startActivity(Intent.createChooser(emailIntent , "Send email..."));

Solution 5:

Post a Comment for "Error: Cannot Attach Empty File In Gmail App Using File Provider"