I try to share a pdf file from android/data/mypackage/files/file.pdf I generate these pdfs also in this app, and when I try to share it, the pdf doesn't appear in on attached files from email, or google drive says something like: "No data to share". Here is my code for sharing pdf:
val aName = intent.getStringExtra("iName")
val file = File(this.getExternalFilesDir(null)?.absolutePath.toString(), "$aName")
val shareIntent = Intent(Intent.ACTION_SEND)
shareIntent.putExtra(Intent.EXTRA_STREAM, file)
shareIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
shareIntent.type = "application/pdf"
startActivity(Intent.createChooser(shareIntent, "share.."))
Toast.makeText(this,"$file",Toast.LENGTH_SHORT).show()

The problem is that you are not using a URI, just sending a path, you need several things.
Provider paths
You have to create
provider_paths.xmlunderxmlfolder inres:Set the provider in the
ManifestunderAplication:Get the URI
Your final code:
I didn't test the code, write it from "memory", let me know if it works for you.