I have implemented a custom content provider serving pdf documents as ParcelFileDescriptor. Files are stored in the local storage marked as PRIVATE. Based on an URI the documents are then handed over to the selected pdf application.
This works for all PDF Viewer applications except adobe reader. Can someone please confirm that adobe reader does not work with content providers? Code below:
When document has been downloaded:
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 viewer apps call 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.