Reputation: 5207
I have a pdf file in location
/data/user/0/com.app.example/files/User/751f8052e.pdf
now I want to open this file on any PDF reader installed in the device.
This is what I am doing so far
Uri imageUri ;
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
{
imageUri = FileProvider.getUriForFile(context , context.getString(R.string.file_provider_authority), PDFFile);
}
else
{
imageUri = Uri.fromFile(PDFFile);
}
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_VIEW);
shareIntent.setDataAndType(imageUri , "application/pdf");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
context.startActivity(shareIntent);
but it is not opening the pdf file. It gave an error toast
Can't open the file
Note: I can't copy the file to some other directory.
Thanks
Upvotes: 0
Views: 84
Reputation: 11214
For the indicated private directory you should always use a file provider.
Upvotes: 1