Added fail safe

This commit is contained in:
M66B 2023-10-14 17:30:17 +02:00
parent 188686365a
commit 96f5bb3e82
1 changed files with 4 additions and 1 deletions

View File

@ -115,7 +115,7 @@ public class AdapterImage extends RecyclerView.Adapter<AdapterImage.ViewHolder>
int max = args.getInt("max");
if ("application/pdf".equals(type)) {
// https://medium.com/@aditya09tyagi/android-pdf-reader-using-pdfrenderer-6daa2dacec1a
// https://developer.android.com/reference/android/graphics/pdf/PdfRenderer
try (ParcelFileDescriptor pfd = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY)) {
try (PdfRenderer pdf = new PdfRenderer(pfd)) {
try (PdfRenderer.Page page = pdf.openPage(0)) {
@ -128,6 +128,9 @@ public class AdapterImage extends RecyclerView.Adapter<AdapterImage.ViewHolder>
return new BitmapDrawable(context.getResources(), bm);
}
}
} catch (Throwable ex) {
Log.w(ex);
return null;
}
} else {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);