Can anyone confirm that Adobe Reader works with a custom content provider?

I have implemented a custom content provider serving PDF documents as ParcelFileDescriptor. Files are stored in local storage named PRIVATE. Based on the URI, the documents are then transferred to the selected pdf application.

This works for all PDF Viewer applications except adobe reader. Can anyone confirm that Adobe Reader does not work with content providers? Code below:

When the document was uploaded:

private void loadDocInReader(String doc) throws ActivityNotFoundException, Exception { Uri uri = Uri.parse(doc); logger.debug("PDF Application ID is: " + pdfAppID); if (this.pdfAppID != null && this.pdfAppID.length() > 0) { boolean pdfApplicationIsInstalled = checkPDFApplicationIsInstalled(this.pdfAppID); if(pdfApplicationIsInstalled) { Intent intent = new Intent(); intent.setPackage(pdfAppID); intent.setData(uri); intent.setType("application/pdf"); startActivity(intent); } else { logger.error("Please install Adobe Reader first!"); } } else { Intent intent = new Intent(); intent.setData(uri); intent.setType("application/pdf"); startActivity(intent); } } 

All other PDF viewing applications use this method except adobe reader:

 public class DocumentProvider extends ContentProvider { @Override public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException { File file = null; try { file = new File(uri.getPath()); logger.debug("Delivering ParcelFileDescriptor for path: " + file.getPath()); return ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY); } catch (FileNotFoundException e) { logger.error("Error loading Document: ",e); } finally { if(file.exists()) { file.delete(); } } return null; } @Override public int delete(Uri uri, String selection, String[] selectionArgs) { return 0; } } 

Adobe Reader always states: "Invalid file path"

Thanks in advance! Kay

+4
source share
2 answers

As far as I can tell, Adobe Reader has clear support for reading files from ContentProviders. In my case, the openFile method is called and returns a valid ParcelFileDescriptor, but Adobe Reader says: "The document cannot be opened." My content provider works great with Drive PDF Viewer, PDF Reader, and QPDF Reader, which are some of the best PDF readers on the Play Store.

Adobe Reader can open PDF attachments in Gmail using the Gmail content provider, but I can’t determine how and why this works.

+1
source

I also have problems with Adobe Acrobat Reader, which do not work with my user provider and finally work. My problem was that the files in the local file space of the application are encrypted and their names are hashed. So Uri was something like:

 content://my.app.provider/08deae8d9ea9bc0b84f94475d868351830e9f7e7 

It works with any PDF viewer app I tested except Adobe Reader. Today I made my last attempt to add the .pdf extension to Content Uri (which is definitely not required), and when Adobe calls the openFile() function, I remove it. VOILA, it works !!!

Update

Please make sure that the _display_name column returned by the ContentProvider as a result of the query query(Uri, String[], String, String[], String) also contains the extension .pdf !!!

Note

Tested Adobe Acrobat Reader version 16.3

0
source

Source: https://habr.com/ru/post/1394852/


All Articles