Pavel Poley
Pavel Poley

Reputation: 5607

Open PDF intent no app found to perform this action

I am using this code to open PDF file that was saved in internal cache dir

private fun openPdfFile(file: File) {
    val intent = Intent(Intent.ACTION_VIEW)
    intent.setDataAndType(Uri.parse(file.path), "application/pdf")
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
    intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
    val chooser = Intent.createChooser(intent, "")
    startActivity(chooser)
}

But I got - "No apps can perform this action"

I have apps on the device that can open the PDF file.

And File provider is registered.

Upvotes: 1

Views: 314

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007584

And File provider is registered

That may be true, but you are not using FileProvider in your code. You need to replace Uri.parse() with FileProvider.getUriForFile().

You also need to take into account that not all users will have access to PDF viewers, by wrapping your startActivity() call in an exception handler.

Upvotes: 1

Related Questions