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
source share