I'm trying to send a PDF file from my app to Whats app, Gmail etc. I'm able to send it to Telegram with the below mentioned code. But in case of Whats app or Gmail i'm getting errors "Sharing of Content Failed", "Cannot attach file".
pdf.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String urlPdf = takeScreenshot(true);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(urlPdf));
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareIntent.setType(".pdf -> application/pdf");
startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.sendto)));
}
});
I would like to know the issue in the code if any or is it due to any permission flaws? Please rectify.