I want to send an email with attached pdf files. When I am trying to send them over URI I get this error message:
android.os.FileUriExposedException: file:///Download/myPDFFile.pdf exposed beyond app through ClipData.Item.getUri()
So I tryed to do the same with the fileprovider. Here I get this error message:
java.lang.IllegalArgumentException: Couldn't find meta-data for provider with authority com.example.digitalpaper.provider
String filename="myPDFFile.pdf";
File testFile = new File(Environment.DIRECTORY_DOWNLOADS, filename);
Uri path = FileProvider.getUriForFile(Objects.requireNonNull(getApplicationContext()),BuildConfig.APPLICATION_ID + ".provider", testFile);
//----------------Sending the Mail----------------//
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("application/pdf");
String to[] = {"xyz@gmx.de",eT_email.getText().toString()};
emailIntent.putExtra(Intent.EXTRA_EMAIL, to);
emailIntent.putExtra(Intent.EXTRA_SUBJECT,"Subject");
//-----------------------Attaching the file---------------------------------//
emailIntent.putExtra(Intent.EXTRA_STREAM, path);
// emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse( "file://"+filelocation));
startActivity(Intent.createChooser(emailIntent,"Send email..."));
I already tried several ways to accomplish that Email attachment but I am never able to access my external storage. Do someone know how to solve that ?