0

well I can store pdf file in external storage correctly. but the problem is when I want to send it via fileProvider to telegram it got this error "unsupported attachment" in telegram app.

this is my code to share pdf:

File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath(), viewModel.getUserData().getCaseNo() + ".pdf");
        Uri uri = FileProvider.getUriForFile(requireContext(), "com.nsard.provider", file);
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.putExtra(Intent.EXTRA_STREAM, uri);
        intent.setClipData(ClipData.newRawUri("", uri))
        intent.setDataAndType(uri, requireContext().getContentResolver().getType(uri));
        intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        Snackbar.make(binding.getRoot(), file.getPath() + "\n" + uri.getPath(), Snackbar.LENGTH_SHORT).show();
        startActivity(Intent.createChooser(intent, "Open with"));

I also try this solution attachment problem but it did not solve.

the point is that in android lower it works correctly but in 10+ face error.

thanks.

Mahdi
  • 3
  • 4

1 Answers1

0

Post Android 10 file access has changed. Please refer to my answer here.

mindoverflow
  • 730
  • 4
  • 13