简体   繁体   中英

PdfRenderer keep crashing in android API 25

I use PdfRenderer to render PDF preview in Android API 25:

var parcelFileDescriptor: ParcelFileDescriptor? = null
var pdfRenderer: PdfRenderer? = null
var firstPage: PdfRenderer.Page? = null
try {
    val file = File(filePath)
    parcelFileDescriptor = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY)
    pdfRenderer = PdfRenderer(parcelFileDescriptor) // it throw exception or crash from here
    firstPage = pdfRenderer.openPage(0)
    // Do something with firstPage
} catch (e: Exception) {
    e.printStackTrace()
} finally {
    firstPage?.close()
    pdfRenderer?.close()
    parcelFileDescriptor?.close()
}

But in first call, it throws java.lang.SecurityException: cannot create document. Error: 4 java.lang.SecurityException: cannot create document. Error: 4 . From 2nd or 3rd call, it is not responding and crash in native. I just call it from only one thread, so there is no concurrency issue. Can anyone help me?

I found trying to open a password protected pdf on Android < P causes the crash: https://issuetracker.google.com/issues/37052344 .

What to do is checking if the pdf file is encrypted or not before opening.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM