sorry for the inconvenience, but I really need help.
I have created a webview and I have added a button to send a file via WhatsApp. Everything works, until the moment of sending the file.
I select the contact, it apparently loads the file (It doesn’t let me view the file) and goes back instantly. then it shows the chat screen but without file to send
The file you are trying to send is in the downloads folder. It’s as if the file is not there.
private fun sharePDF() {
val outputFile = File(
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
"INVOICE.PDF"
)
val uri = FileProvider.getUriForFile(this@MainActivity, "${BuildConfig.APPLICATION_ID}.provider", outputFile)
val share = Intent()
share.action = Intent.ACTION_SEND
share.type = "application/pdf"
share.putExtra(Intent.EXTRA_STREAM, uri)
//share.setPackage("com.whatsapp")
share.setPackage("com.whatsapp.w4b")
startActivity(share)
}
//provider_paths
<external-path
name="external"
path="." />
<external-files-path
name="external_files"
path="." />
<files-path
name="files"
path="." />
manifest
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
I have checked the website and cannot find the solution.
user358939 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.